From 2fd4b0fbc0cc796b704c527cd0820e722d2c2c0e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:09:44 -0500 Subject: [PATCH 01/11] chore: use gapic-generator-python 0.56.2 (#47) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update Java and Python dependencies PiperOrigin-RevId: 408420890 Source-Link: https://github.com/googleapis/googleapis/commit/2921f9fb3bfbd16f6b2da0104373e2b47a80a65e Source-Link: https://github.com/googleapis/googleapis-gen/commit/6598ca8cbbf5226733a099c4506518a5af6ff74c Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjU5OGNhOGNiYmY1MjI2NzMzYTA5OWM0NTA2NTE4YTVhZjZmZjc0YyJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../services/datastream/async_client.py | 13 +- .../services/datastream/client.py | 25 +- .../services/datastream/transports/base.py | 10 +- .../services/datastream/transports/grpc.py | 6 +- .../datastream/transports/grpc_asyncio.py | 6 +- .../datastream_v1alpha1/types/datastream.py | 8 + .../types/datastream_resources.py | 17 ++ .../datastream_v1alpha1/test_datastream.py | 244 +++++++++++++----- 8 files changed, 235 insertions(+), 94 deletions(-) diff --git a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py index 7615a82..fbd4a4d 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py @@ -19,14 +19,17 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core.client_options import ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +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 -OptionalRetry = Union[retries.Retry, object] +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 diff --git a/google/cloud/datastream_v1alpha1/services/datastream/client.py b/google/cloud/datastream_v1alpha1/services/datastream/client.py index 310b934..3c7ff50 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/client.py @@ -14,23 +14,25 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +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 -OptionalRetry = Union[retries.Retry, object] +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 @@ -344,8 +346,15 @@ def __init__( client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. - use_client_cert = bool( - util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( + "true", + "false", + ): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + use_client_cert = ( + os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" ) client_cert_source_func = None diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py index 10f7f7d..6891b5a 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py @@ -18,11 +18,11 @@ import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # 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 diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py index a3b97d4..dd346d4 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +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 diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py index 97a6d19..e4cafda 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py @@ -16,9 +16,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +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 diff --git a/google/cloud/datastream_v1alpha1/types/datastream.py b/google/cloud/datastream_v1alpha1/types/datastream.py index 4fc46ba..cfdf1d3 100644 --- a/google/cloud/datastream_v1alpha1/types/datastream.py +++ b/google/cloud/datastream_v1alpha1/types/datastream.py @@ -72,26 +72,32 @@ class DiscoverConnectionProfileRequest(proto.Message): Must be in the format ``projects/*/locations/*``. connection_profile (google.cloud.datastream_v1alpha1.types.ConnectionProfile): An ad-hoc ConnectionProfile configuration. + This field is a member of `oneof`_ ``target``. connection_profile_name (str): A reference to an existing ConnectionProfile. + This field is a member of `oneof`_ ``target``. recursive (bool): Whether to retrieve the full hierarchy of data objects (TRUE) or only the current level (FALSE). + This field is a member of `oneof`_ ``depth``. recursion_depth (int): The number of hierarchy levels below the current level to be retrieved. + This field is a member of `oneof`_ ``depth``. oracle_rdbms (google.cloud.datastream_v1alpha1.types.OracleRdbms): Oracle RDBMS to enrich with child data objects and metadata. + This field is a member of `oneof`_ ``data_object``. mysql_rdbms (google.cloud.datastream_v1alpha1.types.MysqlRdbms): MySQL RDBMS to enrich with child data objects and metadata. + This field is a member of `oneof`_ ``data_object``. """ @@ -132,9 +138,11 @@ class DiscoverConnectionProfileResponse(proto.Message): Attributes: oracle_rdbms (google.cloud.datastream_v1alpha1.types.OracleRdbms): Enriched Oracle RDBMS object. + This field is a member of `oneof`_ ``data_object``. mysql_rdbms (google.cloud.datastream_v1alpha1.types.MysqlRdbms): Enriched MySQL RDBMS object. + This field is a member of `oneof`_ ``data_object``. """ diff --git a/google/cloud/datastream_v1alpha1/types/datastream_resources.py b/google/cloud/datastream_v1alpha1/types/datastream_resources.py index d5a0f25..4f1da74 100644 --- a/google/cloud/datastream_v1alpha1/types/datastream_resources.py +++ b/google/cloud/datastream_v1alpha1/types/datastream_resources.py @@ -171,9 +171,11 @@ class ForwardSshTunnelConnectivity(proto.Message): Port for the SSH tunnel, default value is 22. password (str): Input only. SSH password. + This field is a member of `oneof`_ ``authentication_method``. private_key (str): Input only. SSH private key. + This field is a member of `oneof`_ ``authentication_method``. """ @@ -346,25 +348,32 @@ class ConnectionProfile(proto.Message): Required. Display name. oracle_profile (google.cloud.datastream_v1alpha1.types.OracleProfile): Oracle ConnectionProfile configuration. + This field is a member of `oneof`_ ``profile``. gcs_profile (google.cloud.datastream_v1alpha1.types.GcsProfile): Cloud Storage ConnectionProfile configuration. + This field is a member of `oneof`_ ``profile``. mysql_profile (google.cloud.datastream_v1alpha1.types.MysqlProfile): MySQL ConnectionProfile configuration. + This field is a member of `oneof`_ ``profile``. no_connectivity (google.cloud.datastream_v1alpha1.types.NoConnectivitySettings): No connectivity option chosen. + This field is a member of `oneof`_ ``connectivity``. static_service_ip_connectivity (google.cloud.datastream_v1alpha1.types.StaticServiceIpConnectivity): Static Service IP connectivity. + This field is a member of `oneof`_ ``connectivity``. forward_ssh_connectivity (google.cloud.datastream_v1alpha1.types.ForwardSshTunnelConnectivity): Forward SSH tunnel connectivity. + This field is a member of `oneof`_ ``connectivity``. private_connectivity (google.cloud.datastream_v1alpha1.types.PrivateConnectivity): Private connectivity. + This field is a member of `oneof`_ ``connectivity``. """ @@ -611,9 +620,11 @@ class SourceConfig(proto.Message): identifier. oracle_source_config (google.cloud.datastream_v1alpha1.types.OracleSourceConfig): Oracle data source configuration + This field is a member of `oneof`_ ``source_stream_config``. mysql_source_config (google.cloud.datastream_v1alpha1.types.MysqlSourceConfig): MySQL data source configuration + This field is a member of `oneof`_ ``source_stream_config``. """ @@ -683,9 +694,11 @@ class GcsDestinationConfig(proto.Message): created. avro_file_format (google.cloud.datastream_v1alpha1.types.AvroFileFormat): AVRO file format configuration. + This field is a member of `oneof`_ ``file_format``. json_file_format (google.cloud.datastream_v1alpha1.types.JsonFileFormat): JSON file format configuration. + This field is a member of `oneof`_ ``file_format``. """ @@ -760,9 +773,11 @@ class Stream(proto.Message): Automatically backfill objects included in the stream source configuration. Specific objects can be excluded. + This field is a member of `oneof`_ ``backfill_strategy``. backfill_none (google.cloud.datastream_v1alpha1.types.Stream.BackfillNoneStrategy): Do not automatically backfill any objects. + This field is a member of `oneof`_ ``backfill_strategy``. errors (Sequence[google.cloud.datastream_v1alpha1.types.Error]): Output only. Errors on the Stream. @@ -795,10 +810,12 @@ class BackfillAllStrategy(proto.Message): oracle_excluded_objects (google.cloud.datastream_v1alpha1.types.OracleRdbms): Oracle data source objects to avoid backfilling. + This field is a member of `oneof`_ ``excluded_objects``. mysql_excluded_objects (google.cloud.datastream_v1alpha1.types.MysqlRdbms): MySQL data source objects to avoid backfilling. + This field is a member of `oneof`_ ``excluded_objects``. """ diff --git a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py index efd3ae3..90c2b27 100644 --- a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py +++ b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py @@ -639,7 +639,9 @@ def test_list_connection_profiles_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_connection_profiles_flattened_error(): @@ -675,7 +677,9 @@ async def test_list_connection_profiles_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1034,7 +1038,9 @@ def test_get_connection_profile_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_connection_profile_flattened_error(): @@ -1070,7 +1076,9 @@ async def test_get_connection_profile_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1249,11 +1257,15 @@ def test_create_connection_profile_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].connection_profile == datastream_resources.ConnectionProfile( - name="name_value" - ) - assert args[0].connection_profile_id == "connection_profile_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].connection_profile + mock_val = datastream_resources.ConnectionProfile(name="name_value") + assert arg == mock_val + arg = args[0].connection_profile_id + mock_val = "connection_profile_id_value" + assert arg == mock_val def test_create_connection_profile_flattened_error(): @@ -1300,11 +1312,15 @@ async def test_create_connection_profile_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].connection_profile == datastream_resources.ConnectionProfile( - name="name_value" - ) - assert args[0].connection_profile_id == "connection_profile_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].connection_profile + mock_val = datastream_resources.ConnectionProfile(name="name_value") + assert arg == mock_val + arg = args[0].connection_profile_id + mock_val = "connection_profile_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1493,10 +1509,12 @@ def test_update_connection_profile_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].connection_profile == datastream_resources.ConnectionProfile( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].connection_profile + mock_val = datastream_resources.ConnectionProfile(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_connection_profile_flattened_error(): @@ -1541,10 +1559,12 @@ async def test_update_connection_profile_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].connection_profile == datastream_resources.ConnectionProfile( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].connection_profile + mock_val = datastream_resources.ConnectionProfile(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 @@ -1721,7 +1741,9 @@ def test_delete_connection_profile_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_connection_profile_flattened_error(): @@ -1757,7 +1779,9 @@ async def test_delete_connection_profile_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2073,7 +2097,9 @@ def test_list_streams_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_streams_flattened_error(): @@ -2107,7 +2133,9 @@ async def test_list_streams_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2426,7 +2454,9 @@ def test_get_stream_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_stream_flattened_error(): @@ -2460,7 +2490,9 @@ async def test_get_stream_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2624,9 +2656,15 @@ def test_create_stream_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].stream == datastream_resources.Stream(name="name_value") - assert args[0].stream_id == "stream_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].stream + mock_val = datastream_resources.Stream(name="name_value") + assert arg == mock_val + arg = args[0].stream_id + mock_val = "stream_id_value" + assert arg == mock_val def test_create_stream_flattened_error(): @@ -2667,9 +2705,15 @@ async def test_create_stream_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].stream == datastream_resources.Stream(name="name_value") - assert args[0].stream_id == "stream_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].stream + mock_val = datastream_resources.Stream(name="name_value") + assert arg == mock_val + arg = args[0].stream_id + mock_val = "stream_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2835,8 +2879,12 @@ def test_update_stream_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].stream == datastream_resources.Stream(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].stream + mock_val = datastream_resources.Stream(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_stream_flattened_error(): @@ -2875,8 +2923,12 @@ async def test_update_stream_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].stream == datastream_resources.Stream(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].stream + mock_val = datastream_resources.Stream(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 @@ -3038,7 +3090,9 @@ def test_delete_stream_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_stream_flattened_error(): @@ -3072,7 +3126,9 @@ async def test_delete_stream_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3371,7 +3427,9 @@ def test_fetch_static_ips_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_fetch_static_ips_flattened_error(): @@ -3405,7 +3463,9 @@ async def test_fetch_static_ips_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3694,11 +3754,15 @@ def test_create_private_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].private_connection == datastream_resources.PrivateConnection( - name="name_value" - ) - assert args[0].private_connection_id == "private_connection_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].private_connection + mock_val = datastream_resources.PrivateConnection(name="name_value") + assert arg == mock_val + arg = args[0].private_connection_id + mock_val = "private_connection_id_value" + assert arg == mock_val def test_create_private_connection_flattened_error(): @@ -3745,11 +3809,15 @@ async def test_create_private_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].private_connection == datastream_resources.PrivateConnection( - name="name_value" - ) - assert args[0].private_connection_id == "private_connection_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].private_connection + mock_val = datastream_resources.PrivateConnection(name="name_value") + assert arg == mock_val + arg = args[0].private_connection_id + mock_val = "private_connection_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3940,7 +4008,9 @@ def test_get_private_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_private_connection_flattened_error(): @@ -3976,7 +4046,9 @@ async def test_get_private_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4158,7 +4230,9 @@ def test_list_private_connections_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_private_connections_flattened_error(): @@ -4194,7 +4268,9 @@ async def test_list_private_connections_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4541,7 +4617,9 @@ def test_delete_private_connection_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_private_connection_flattened_error(): @@ -4577,7 +4655,9 @@ async def test_delete_private_connection_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4741,9 +4821,15 @@ def test_create_route_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].route == datastream_resources.Route(name="name_value") - assert args[0].route_id == "route_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].route + mock_val = datastream_resources.Route(name="name_value") + assert arg == mock_val + arg = args[0].route_id + mock_val = "route_id_value" + assert arg == mock_val def test_create_route_flattened_error(): @@ -4784,9 +4870,15 @@ async def test_create_route_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].route == datastream_resources.Route(name="name_value") - assert args[0].route_id == "route_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].route + mock_val = datastream_resources.Route(name="name_value") + assert arg == mock_val + arg = args[0].route_id + mock_val = "route_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4965,7 +5057,9 @@ def test_get_route_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_route_flattened_error(): @@ -4999,7 +5093,9 @@ async def test_get_route_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5168,7 +5264,9 @@ def test_list_routes_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_routes_flattened_error(): @@ -5202,7 +5300,9 @@ async def test_list_routes_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5500,7 +5600,9 @@ def test_delete_route_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_route_flattened_error(): @@ -5534,7 +5636,9 @@ async def test_delete_route_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio From 6ed5d1f5d6d2cf299d01541b20d26c22328d7716 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:05:09 -0500 Subject: [PATCH 02/11] chore(python): add .github/CODEOWNERS as a templated file (#48) Source-Link: https://github.com/googleapis/synthtool/commit/c5026b3217973a8db55db8ee85feee0e9a65e295 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 Co-authored-by: Owl Bot --- .github/.OwlBot.lock.yaml | 2 +- .github/CODEOWNERS | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 108063d..7519fa3 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:4ee57a76a176ede9087c14330c625a71553cf9c72828b2c0ca12f5338171ba60 + digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index be888a9..44cc868 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,9 +3,10 @@ # # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax +# Note: This file is autogenerated. To make changes to the codeowner team, please update .repo-metadata.json. -# The @googleapis/yoshi-python is the default owner for changes in this repo -* @googleapis/yoshi-python - +# @googleapis/yoshi-python is the default owner for changes in this repo +* @googleapis/yoshi-python +# @googleapis/python-samples-owners is the default owner for samples changes /samples/ @googleapis/python-samples-owners From d8b79fadc4125e846b91c0653195d844a61a9c23 Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Tue, 16 Nov 2021 11:10:03 -0500 Subject: [PATCH 03/11] chore: update doc links from googleapis.dev to cloud.google.com (#49) --- .repo-metadata.json | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index 0e237eb..68dda46 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,7 +2,7 @@ "name": "datastream", "name_pretty": "Datastream", "product_documentation": "https://cloud.google.com/datastream/", - "client_documentation": "https://googleapis.dev/python/datastream/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/datastream/latest", "issue_tracker": "", "release_level": "alpha", "language": "python", diff --git a/README.rst b/README.rst index 4bbcea2..cd3ca2a 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ Python Client for Datastream .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-datastream.svg :target: https://pypi.org/project/google-cloud-datastream/ .. _Datastream: https://cloud.google.com/datastream -.. _Client Library Documentation: https://googleapis.dev/python/datastream/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/datastream/latest .. _Product Documentation: https://cloud.google.com/datastream Quick Start From 7a329c0fa11d5505783b9e9e3a70ac8e15c41a10 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 28 Dec 2021 13:20:29 -0500 Subject: [PATCH 04/11] chore: update .repo-metadata.json (#52) --- .repo-metadata.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.repo-metadata.json b/.repo-metadata.json index 68dda46..f66994c 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -4,12 +4,13 @@ "product_documentation": "https://cloud.google.com/datastream/", "client_documentation": "https://cloud.google.com/python/docs/reference/datastream/latest", "issue_tracker": "", - "release_level": "alpha", + "release_level": "preview", "language": "python", "library_type": "GAPIC_AUTO", "repo": "googleapis/python-datastream", "distribution_name": "google-cloud-datastream", "api_id": "datastream.googleapis.com", "default_version": "v1alpha1", - "codeowner_team": "" + "codeowner_team": "", + "api_shortname": "datastream" } From faf1efd0ded056486a0b5c3070b26273371b78d2 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:02:26 +0000 Subject: [PATCH 05/11] chore: use python-samples-reviewers (#54) --- .github/.OwlBot.lock.yaml | 2 +- .github/CODEOWNERS | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 7519fa3..f33299d 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7 + digest: sha256:899d5d7cc340fa8ef9d8ae1a8cfba362c6898584f779e156f25ee828ba824610 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 44cc868..e446644 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,5 +8,5 @@ # @googleapis/yoshi-python is the default owner for changes in this repo * @googleapis/yoshi-python -# @googleapis/python-samples-owners is the default owner for samples changes -/samples/ @googleapis/python-samples-owners +# @googleapis/python-samples-reviewers is the default owner for samples changes +/samples/ @googleapis/python-samples-reviewers From 9a21e440000ee5f629fcb2302a36360e6afea734 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Sat, 8 Jan 2022 06:59:12 -0500 Subject: [PATCH 06/11] chore: use gapic-generator-python 0.58.4 (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: use gapic-generator-python 0.58.4 fix: provide appropriate mock values for message body fields committer: dovs PiperOrigin-RevId: 419025932 Source-Link: https://github.com/googleapis/googleapis/commit/73da6697f598f1ba30618924936a59f8e457ec89 Source-Link: https://github.com/googleapis/googleapis-gen/commit/46df624a54b9ed47c1a7eefb7a49413cf7b82f98 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDZkZjYyNGE1NGI5ZWQ0N2MxYTdlZWZiN2E0OTQxM2NmN2I4MmY5OCJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../services/datastream/transports/base.py | 1 - .../datastream_v1alpha1/test_datastream.py | 279 +++++++----------- 2 files changed, 109 insertions(+), 171 deletions(-) diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py index 6891b5a..43d4725 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/base.py @@ -104,7 +104,6 @@ def __init__( 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 diff --git a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py index 90c2b27..4568aef 100644 --- a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py +++ b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py @@ -245,20 +245,20 @@ def test_datastream_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + 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() + 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(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -315,7 +315,7 @@ def test_datastream_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -410,7 +410,7 @@ def test_datastream_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -441,7 +441,7 @@ def test_datastream_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -472,9 +472,10 @@ def test_datastream_client_client_options_from_dict(): ) -def test_list_connection_profiles( - transport: str = "grpc", request_type=datastream.ListConnectionProfilesRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.ListConnectionProfilesRequest, dict,] +) +def test_list_connection_profiles(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -504,10 +505,6 @@ def test_list_connection_profiles( assert response.unreachable == ["unreachable_value"] -def test_list_connection_profiles_from_dict(): - test_list_connection_profiles(request_type=dict) - - def test_list_connection_profiles_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. @@ -694,8 +691,10 @@ async def test_list_connection_profiles_flattened_error_async(): ) -def test_list_connection_profiles_pager(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_connection_profiles_pager(transport_name: str = "grpc"): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -742,8 +741,10 @@ def test_list_connection_profiles_pager(): ) -def test_list_connection_profiles_pages(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_connection_profiles_pages(transport_name: str = "grpc"): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -868,9 +869,10 @@ async def test_list_connection_profiles_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_connection_profile( - transport: str = "grpc", request_type=datastream.GetConnectionProfileRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.GetConnectionProfileRequest, dict,] +) +def test_get_connection_profile(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -905,10 +907,6 @@ def test_get_connection_profile( assert response.display_name == "display_name_value" -def test_get_connection_profile_from_dict(): - test_get_connection_profile(request_type=dict) - - def test_get_connection_profile_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. @@ -1093,9 +1091,10 @@ async def test_get_connection_profile_flattened_error_async(): ) -def test_create_connection_profile( - transport: str = "grpc", request_type=datastream.CreateConnectionProfileRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.CreateConnectionProfileRequest, dict,] +) +def test_create_connection_profile(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1121,10 +1120,6 @@ def test_create_connection_profile( assert isinstance(response, future.Future) -def test_create_connection_profile_from_dict(): - test_create_connection_profile(request_type=dict) - - def test_create_connection_profile_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. @@ -1340,9 +1335,10 @@ async def test_create_connection_profile_flattened_error_async(): ) -def test_update_connection_profile( - transport: str = "grpc", request_type=datastream.UpdateConnectionProfileRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.UpdateConnectionProfileRequest, dict,] +) +def test_update_connection_profile(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1368,10 +1364,6 @@ def test_update_connection_profile( assert isinstance(response, future.Future) -def test_update_connection_profile_from_dict(): - test_update_connection_profile(request_type=dict) - - def test_update_connection_profile_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. @@ -1583,9 +1575,10 @@ async def test_update_connection_profile_flattened_error_async(): ) -def test_delete_connection_profile( - transport: str = "grpc", request_type=datastream.DeleteConnectionProfileRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.DeleteConnectionProfileRequest, dict,] +) +def test_delete_connection_profile(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1611,10 +1604,6 @@ def test_delete_connection_profile( assert isinstance(response, future.Future) -def test_delete_connection_profile_from_dict(): - test_delete_connection_profile(request_type=dict) - - def test_delete_connection_profile_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. @@ -1796,9 +1785,10 @@ async def test_delete_connection_profile_flattened_error_async(): ) -def test_discover_connection_profile( - transport: str = "grpc", request_type=datastream.DiscoverConnectionProfileRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.DiscoverConnectionProfileRequest, dict,] +) +def test_discover_connection_profile(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1830,10 +1820,6 @@ def test_discover_connection_profile( assert isinstance(response, datastream.DiscoverConnectionProfileResponse) -def test_discover_connection_profile_from_dict(): - test_discover_connection_profile(request_type=dict) - - def test_discover_connection_profile_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. @@ -1943,9 +1929,8 @@ async def test_discover_connection_profile_field_headers_async(): assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] -def test_list_streams( - transport: str = "grpc", request_type=datastream.ListStreamsRequest -): +@pytest.mark.parametrize("request_type", [datastream.ListStreamsRequest, dict,]) +def test_list_streams(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1973,10 +1958,6 @@ def test_list_streams( assert response.unreachable == ["unreachable_value"] -def test_list_streams_from_dict(): - test_list_streams(request_type=dict) - - def test_list_streams_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. @@ -2150,8 +2131,10 @@ async def test_list_streams_flattened_error_async(): ) -def test_list_streams_pager(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_streams_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_streams), "__call__") as call: @@ -2188,8 +2171,10 @@ def test_list_streams_pager(): assert all(isinstance(i, datastream_resources.Stream) for i in results) -def test_list_streams_pages(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_streams_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_streams), "__call__") as call: @@ -2288,7 +2273,8 @@ async def test_list_streams_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_stream(transport: str = "grpc", request_type=datastream.GetStreamRequest): +@pytest.mark.parametrize("request_type", [datastream.GetStreamRequest, dict,]) +def test_get_stream(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2328,10 +2314,6 @@ def test_get_stream(transport: str = "grpc", request_type=datastream.GetStreamRe assert response.state == datastream_resources.Stream.State.CREATED -def test_get_stream_from_dict(): - test_get_stream(request_type=dict) - - def test_get_stream_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. @@ -2507,9 +2489,8 @@ async def test_get_stream_flattened_error_async(): ) -def test_create_stream( - transport: str = "grpc", request_type=datastream.CreateStreamRequest -): +@pytest.mark.parametrize("request_type", [datastream.CreateStreamRequest, dict,]) +def test_create_stream(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2533,10 +2514,6 @@ def test_create_stream( assert isinstance(response, future.Future) -def test_create_stream_from_dict(): - test_create_stream(request_type=dict) - - def test_create_stream_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. @@ -2731,9 +2708,8 @@ async def test_create_stream_flattened_error_async(): ) -def test_update_stream( - transport: str = "grpc", request_type=datastream.UpdateStreamRequest -): +@pytest.mark.parametrize("request_type", [datastream.UpdateStreamRequest, dict,]) +def test_update_stream(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2757,10 +2733,6 @@ def test_update_stream( assert isinstance(response, future.Future) -def test_update_stream_from_dict(): - test_update_stream(request_type=dict) - - def test_update_stream_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. @@ -2945,9 +2917,8 @@ async def test_update_stream_flattened_error_async(): ) -def test_delete_stream( - transport: str = "grpc", request_type=datastream.DeleteStreamRequest -): +@pytest.mark.parametrize("request_type", [datastream.DeleteStreamRequest, dict,]) +def test_delete_stream(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2971,10 +2942,6 @@ def test_delete_stream( assert isinstance(response, future.Future) -def test_delete_stream_from_dict(): - test_delete_stream(request_type=dict) - - def test_delete_stream_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. @@ -3143,9 +3110,8 @@ async def test_delete_stream_flattened_error_async(): ) -def test_fetch_errors( - transport: str = "grpc", request_type=datastream.FetchErrorsRequest -): +@pytest.mark.parametrize("request_type", [datastream.FetchErrorsRequest, dict,]) +def test_fetch_errors(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3169,10 +3135,6 @@ def test_fetch_errors( assert isinstance(response, future.Future) -def test_fetch_errors_from_dict(): - test_fetch_errors(request_type=dict) - - def test_fetch_errors_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. @@ -3273,9 +3235,8 @@ async def test_fetch_errors_field_headers_async(): assert ("x-goog-request-params", "stream=stream/value",) in kw["metadata"] -def test_fetch_static_ips( - transport: str = "grpc", request_type=datastream.FetchStaticIpsRequest -): +@pytest.mark.parametrize("request_type", [datastream.FetchStaticIpsRequest, dict,]) +def test_fetch_static_ips(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3303,10 +3264,6 @@ def test_fetch_static_ips( assert response.next_page_token == "next_page_token_value" -def test_fetch_static_ips_from_dict(): - test_fetch_static_ips(request_type=dict) - - def test_fetch_static_ips_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. @@ -3480,8 +3437,10 @@ async def test_fetch_static_ips_flattened_error_async(): ) -def test_fetch_static_ips_pager(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_fetch_static_ips_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: @@ -3511,8 +3470,10 @@ def test_fetch_static_ips_pager(): assert all(isinstance(i, str) for i in results) -def test_fetch_static_ips_pages(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_fetch_static_ips_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: @@ -3590,9 +3551,10 @@ async def test_fetch_static_ips_async_pages(): assert page_.raw_page.next_page_token == token -def test_create_private_connection( - transport: str = "grpc", request_type=datastream.CreatePrivateConnectionRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.CreatePrivateConnectionRequest, dict,] +) +def test_create_private_connection(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3618,10 +3580,6 @@ def test_create_private_connection( assert isinstance(response, future.Future) -def test_create_private_connection_from_dict(): - test_create_private_connection(request_type=dict) - - def test_create_private_connection_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. @@ -3837,9 +3795,10 @@ async def test_create_private_connection_flattened_error_async(): ) -def test_get_private_connection( - transport: str = "grpc", request_type=datastream.GetPrivateConnectionRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.GetPrivateConnectionRequest, dict,] +) +def test_get_private_connection(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -3872,10 +3831,6 @@ def test_get_private_connection( assert response.state == datastream_resources.PrivateConnection.State.CREATING -def test_get_private_connection_from_dict(): - test_get_private_connection(request_type=dict) - - def test_get_private_connection_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. @@ -4063,9 +4018,10 @@ async def test_get_private_connection_flattened_error_async(): ) -def test_list_private_connections( - transport: str = "grpc", request_type=datastream.ListPrivateConnectionsRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.ListPrivateConnectionsRequest, dict,] +) +def test_list_private_connections(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4095,10 +4051,6 @@ def test_list_private_connections( assert response.unreachable == ["unreachable_value"] -def test_list_private_connections_from_dict(): - test_list_private_connections(request_type=dict) - - def test_list_private_connections_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. @@ -4285,8 +4237,10 @@ async def test_list_private_connections_flattened_error_async(): ) -def test_list_private_connections_pager(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_private_connections_pager(transport_name: str = "grpc"): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4333,8 +4287,10 @@ def test_list_private_connections_pager(): ) -def test_list_private_connections_pages(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_private_connections_pages(transport_name: str = "grpc"): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4459,9 +4415,10 @@ async def test_list_private_connections_async_pages(): assert page_.raw_page.next_page_token == token -def test_delete_private_connection( - transport: str = "grpc", request_type=datastream.DeletePrivateConnectionRequest -): +@pytest.mark.parametrize( + "request_type", [datastream.DeletePrivateConnectionRequest, dict,] +) +def test_delete_private_connection(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4487,10 +4444,6 @@ def test_delete_private_connection( assert isinstance(response, future.Future) -def test_delete_private_connection_from_dict(): - test_delete_private_connection(request_type=dict) - - def test_delete_private_connection_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. @@ -4672,9 +4625,8 @@ async def test_delete_private_connection_flattened_error_async(): ) -def test_create_route( - transport: str = "grpc", request_type=datastream.CreateRouteRequest -): +@pytest.mark.parametrize("request_type", [datastream.CreateRouteRequest, dict,]) +def test_create_route(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4698,10 +4650,6 @@ def test_create_route( assert isinstance(response, future.Future) -def test_create_route_from_dict(): - test_create_route(request_type=dict) - - def test_create_route_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. @@ -4896,7 +4844,8 @@ async def test_create_route_flattened_error_async(): ) -def test_get_route(transport: str = "grpc", request_type=datastream.GetRouteRequest): +@pytest.mark.parametrize("request_type", [datastream.GetRouteRequest, dict,]) +def test_get_route(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -4929,10 +4878,6 @@ def test_get_route(transport: str = "grpc", request_type=datastream.GetRouteRequ assert response.destination_port == 1734 -def test_get_route_from_dict(): - test_get_route(request_type=dict) - - def test_get_route_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. @@ -5110,9 +5055,8 @@ async def test_get_route_flattened_error_async(): ) -def test_list_routes( - transport: str = "grpc", request_type=datastream.ListRoutesRequest -): +@pytest.mark.parametrize("request_type", [datastream.ListRoutesRequest, dict,]) +def test_list_routes(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5140,10 +5084,6 @@ def test_list_routes( assert response.unreachable == ["unreachable_value"] -def test_list_routes_from_dict(): - test_list_routes(request_type=dict) - - def test_list_routes_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. @@ -5317,8 +5257,10 @@ async def test_list_routes_flattened_error_async(): ) -def test_list_routes_pager(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_routes_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_routes), "__call__") as call: @@ -5355,8 +5297,10 @@ def test_list_routes_pager(): assert all(isinstance(i, datastream_resources.Route) for i in results) -def test_list_routes_pages(): - client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_routes_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_routes), "__call__") as call: @@ -5455,9 +5399,8 @@ async def test_list_routes_async_pages(): assert page_.raw_page.next_page_token == token -def test_delete_route( - transport: str = "grpc", request_type=datastream.DeleteRouteRequest -): +@pytest.mark.parametrize("request_type", [datastream.DeleteRouteRequest, dict,]) +def test_delete_route(request_type, transport: str = "grpc"): client = DatastreamClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -5481,10 +5424,6 @@ def test_delete_route( assert isinstance(response, future.Future) -def test_delete_route_from_dict(): - test_delete_route(request_type=dict) - - def test_delete_route_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. @@ -6282,7 +6221,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( From da6f46e5db32fbe3309a6b5ebaffcc2595c3957f Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 14 Jan 2022 16:24:13 +0000 Subject: [PATCH 07/11] chore(python): update release.sh to use keystore (#56) build: switch to release-please for tagging --- .github/.OwlBot.lock.yaml | 2 +- .github/release-please.yml | 1 + .github/release-trigger.yml | 1 + .kokoro/release.sh | 2 +- .kokoro/release/common.cfg | 12 +++++++++++- 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .github/release-trigger.yml diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index f33299d..eecb84c 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,3 @@ docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:899d5d7cc340fa8ef9d8ae1a8cfba362c6898584f779e156f25ee828ba824610 + digest: sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad0..466597e 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,2 @@ releaseType: python +handleGHRelease: true diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.kokoro/release.sh b/.kokoro/release.sh index b23ec9d..087ea8d 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-datastream python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 5a29569..16de51d 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-datastream/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } From 9fe18f707a9b0685e75c40098aadb2e24466e95f Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 21 Jan 2022 06:04:03 -0500 Subject: [PATCH 08/11] ci(python): run lint / unit tests / docs as GH actions (#57) * ci(python): run lint / unit tests / docs as GH actions Source-Link: https://github.com/googleapis/synthtool/commit/57be0cdb0b94e1669cee0ca38d790de1dfdbcd44 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 * add commit to trigger gh action Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou --- .github/.OwlBot.lock.yaml | 16 +++++++++- .github/workflows/docs.yml | 38 +++++++++++++++++++++++ .github/workflows/lint.yml | 25 +++++++++++++++ .github/workflows/unittest.yml | 57 ++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/unittest.yml diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index eecb84c..b668c04 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,3 +1,17 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:ae600f36b6bc972b368367b6f83a1d91ec2c82a4a116b383d67d547c56fe6de3 + digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6 + diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..f7b8344 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,38 @@ +on: + pull_request: + branches: + - main +name: docs +jobs: + docs: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docs + run: | + nox -s docs + docfx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run docfx + run: | + nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..1e8b05c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +on: + pull_request: + branches: + - main +name: lint +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run lint + run: | + nox -s lint + - name: Run lint_setup_py + run: | + nox -s lint_setup_py diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..074ee25 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,57 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.6', '3.7', '3.8', '3.9', '3.10'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-${{ matrix.python }} + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v2 + with: + name: coverage-artifacts + path: .coverage-results/ + - name: Report coverage results + run: | + coverage combine .coverage-results/.coverage* + coverage report --show-missing --fail-under=100 From 88cf10a130116cbc199d6279b00959ad40946671 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 25 Jan 2022 12:50:07 -0500 Subject: [PATCH 09/11] feat: add api key support (#58) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: upgrade gapic-generator-java, gax-java and gapic-generator-python PiperOrigin-RevId: 423842556 Source-Link: https://github.com/googleapis/googleapis/commit/a616ca08f4b1416abbac7bc5dd6d61c791756a81 Source-Link: https://github.com/googleapis/googleapis-gen/commit/29b938c58c1e51d019f2ee539d55dc0a3c86a905 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjliOTM4YzU4YzFlNTFkMDE5ZjJlZTUzOWQ1NWRjMGEzYzg2YTkwNSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../services/datastream/async_client.py | 38 +++++- .../services/datastream/client.py | 127 ++++++++++++------ .../datastream_v1alpha1/test_datastream.py | 124 +++++++++++++++++ 3 files changed, 245 insertions(+), 44 deletions(-) diff --git a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py index fbd4a4d..1f19b42 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py @@ -16,7 +16,7 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Optional, Sequence, Tuple, Type, Union import pkg_resources from google.api_core.client_options import ClientOptions @@ -116,6 +116,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): 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 variabel 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 DatastreamClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DatastreamTransport: """Returns the transport used by the client instance. diff --git a/google/cloud/datastream_v1alpha1/services/datastream/client.py b/google/cloud/datastream_v1alpha1/services/datastream/client.py index 3c7ff50..9ccdfe1 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/client.py @@ -295,6 +295,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: 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 variabel 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, *, @@ -345,57 +412,22 @@ def __init__( if client_options is None: client_options = client_options_lib.ClientOptions() - # Create SSL credentials for mutual TLS if needed. - if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in ( - "true", - "false", - ): - raise ValueError( - "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" - ) - use_client_cert = ( - os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true" + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - if is_mtls: - client_cert_source_func = mtls.default_client_cert_source() - else: - client_cert_source_func = None - - # Figure out which api endpoint to use. - if client_options.api_endpoint is not None: - api_endpoint = client_options.api_endpoint - else: - use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") - if use_mtls_env == "never": - api_endpoint = self.DEFAULT_ENDPOINT - elif use_mtls_env == "always": - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - elif use_mtls_env == "auto": - if is_mtls: - api_endpoint = self.DEFAULT_MTLS_ENDPOINT - else: - api_endpoint = self.DEFAULT_ENDPOINT - else: - raise MutualTLSChannelError( - "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted " - "values: never, auto, always" - ) + 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, DatastreamTransport): # transport is a DatastreamTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: raise ValueError( "When providing a transport instance, " "provide its credentials directly." @@ -407,6 +439,15 @@ def __init__( ) 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, diff --git a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py index 4568aef..4e7340e 100644 --- a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py +++ b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py @@ -392,6 +392,83 @@ def test_datastream_client_mtls_env_auto( ) +@pytest.mark.parametrize("client_class", [DatastreamClient, DatastreamAsyncClient]) +@mock.patch.object( + DatastreamClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatastreamClient) +) +@mock.patch.object( + DatastreamAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatastreamAsyncClient), +) +def test_datastream_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", [ @@ -5612,6 +5689,23 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatastreamClient(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 = DatastreamClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DatastreamGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), @@ -6286,3 +6380,33 @@ def test_client_ctx(): with client: pass close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (DatastreamClient, transports.DatastreamGrpcTransport), + (DatastreamAsyncClient, transports.DatastreamGrpcAsyncIOTransport), + ], +) +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, + ) From 28dab85bf3b4ad937760d5219623793936e39731 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 3 Feb 2022 12:38:46 +0000 Subject: [PATCH 10/11] feat: add datastream v1 (#61) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 425538443 Source-Link: https://github.com/googleapis/googleapis/commit/07cb2ca17029dbd47ce640ed4d9b169fd5afa698 Source-Link: https://github.com/googleapis/googleapis-gen/commit/66d72baf59afe47c026154bf8ebd27bf29c3e554 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjZkNzJiYWY1OWFmZTQ3YzAyNjE1NGJmOGViZDI3YmYyOWMzZTU1NCJ9 fix: remove `FetchErrorsRequest` and `FetchErrorsResponse` fix: remove `NoConnectivitySettings` fix: remove `GcsFileFormat` and `SchemaFileFormat` --- .repo-metadata.json | 2 +- docs/datastream_v1/datastream.rst | 10 + docs/datastream_v1/services.rst | 6 + docs/datastream_v1/types.rst | 7 + docs/index.rst | 11 + google/cloud/datastream/__init__.py | 194 +- google/cloud/datastream_v1/__init__.py | 162 + .../cloud/datastream_v1/gapic_metadata.json | 273 + google/cloud/datastream_v1/py.typed | 2 + .../cloud/datastream_v1/services/__init__.py | 15 + .../services/datastream/__init__.py | 22 + .../services/datastream/async_client.py | 2299 +++++ .../services/datastream/client.py | 2597 ++++++ .../services/datastream/pagers.py | 796 ++ .../datastream/transports/__init__.py | 33 + .../services/datastream/transports/base.py | 500 ++ .../services/datastream/transports/grpc.py | 959 +++ .../datastream/transports/grpc_asyncio.py | 982 +++ google/cloud/datastream_v1/types/__init__.py | 160 + .../cloud/datastream_v1/types/datastream.py | 1072 +++ .../types/datastream_resources.py | 1082 +++ .../services/datastream/async_client.py | 38 +- .../services/datastream/client.py | 38 +- .../services/datastream/transports/grpc.py | 7 +- .../datastream/transports/grpc_asyncio.py | 7 +- .../types/datastream_resources.py | 3 +- scripts/fixup_datastream_v1_keywords.py | 200 + tests/unit/gapic/datastream_v1/__init__.py | 15 + .../gapic/datastream_v1/test_datastream.py | 7570 +++++++++++++++++ .../datastream_v1alpha1/test_datastream.py | 70 +- 30 files changed, 18972 insertions(+), 160 deletions(-) create mode 100644 docs/datastream_v1/datastream.rst create mode 100644 docs/datastream_v1/services.rst create mode 100644 docs/datastream_v1/types.rst create mode 100644 google/cloud/datastream_v1/__init__.py create mode 100644 google/cloud/datastream_v1/gapic_metadata.json create mode 100644 google/cloud/datastream_v1/py.typed create mode 100644 google/cloud/datastream_v1/services/__init__.py create mode 100644 google/cloud/datastream_v1/services/datastream/__init__.py create mode 100644 google/cloud/datastream_v1/services/datastream/async_client.py create mode 100644 google/cloud/datastream_v1/services/datastream/client.py create mode 100644 google/cloud/datastream_v1/services/datastream/pagers.py create mode 100644 google/cloud/datastream_v1/services/datastream/transports/__init__.py create mode 100644 google/cloud/datastream_v1/services/datastream/transports/base.py create mode 100644 google/cloud/datastream_v1/services/datastream/transports/grpc.py create mode 100644 google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py create mode 100644 google/cloud/datastream_v1/types/__init__.py create mode 100644 google/cloud/datastream_v1/types/datastream.py create mode 100644 google/cloud/datastream_v1/types/datastream_resources.py create mode 100644 scripts/fixup_datastream_v1_keywords.py create mode 100644 tests/unit/gapic/datastream_v1/__init__.py create mode 100644 tests/unit/gapic/datastream_v1/test_datastream.py diff --git a/.repo-metadata.json b/.repo-metadata.json index f66994c..d160401 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -10,7 +10,7 @@ "repo": "googleapis/python-datastream", "distribution_name": "google-cloud-datastream", "api_id": "datastream.googleapis.com", - "default_version": "v1alpha1", + "default_version": "v1", "codeowner_team": "", "api_shortname": "datastream" } diff --git a/docs/datastream_v1/datastream.rst b/docs/datastream_v1/datastream.rst new file mode 100644 index 0000000..b966db4 --- /dev/null +++ b/docs/datastream_v1/datastream.rst @@ -0,0 +1,10 @@ +Datastream +---------------------------- + +.. automodule:: google.cloud.datastream_v1.services.datastream + :members: + :inherited-members: + +.. automodule:: google.cloud.datastream_v1.services.datastream.pagers + :members: + :inherited-members: diff --git a/docs/datastream_v1/services.rst b/docs/datastream_v1/services.rst new file mode 100644 index 0000000..ec9e529 --- /dev/null +++ b/docs/datastream_v1/services.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Datastream v1 API +=========================================== +.. toctree:: + :maxdepth: 2 + + datastream diff --git a/docs/datastream_v1/types.rst b/docs/datastream_v1/types.rst new file mode 100644 index 0000000..3e49a8f --- /dev/null +++ b/docs/datastream_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Datastream v1 API +======================================== + +.. automodule:: google.cloud.datastream_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/index.rst b/docs/index.rst index 2a19935..d07e1b1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,6 +2,17 @@ .. include:: multiprocessing.rst +This package includes clients for multiple versions of Datastream. +By default, you will get version ``datastream_v1``. + + +API Reference +------------- +.. toctree:: + :maxdepth: 2 + + datastream_v1/services + datastream_v1/types API Reference ------------- diff --git a/google/cloud/datastream/__init__.py b/google/cloud/datastream/__init__.py index 1a49f1c..2fb1855 100644 --- a/google/cloud/datastream/__init__.py +++ b/google/cloud/datastream/__init__.py @@ -14,122 +14,86 @@ # limitations under the License. # -from google.cloud.datastream_v1alpha1.services.datastream.client import DatastreamClient -from google.cloud.datastream_v1alpha1.services.datastream.async_client import ( +from google.cloud.datastream_v1.services.datastream.client import DatastreamClient +from google.cloud.datastream_v1.services.datastream.async_client import ( DatastreamAsyncClient, ) -from google.cloud.datastream_v1alpha1.types.datastream import ( - CreateConnectionProfileRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - CreatePrivateConnectionRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import CreateRouteRequest -from google.cloud.datastream_v1alpha1.types.datastream import CreateStreamRequest -from google.cloud.datastream_v1alpha1.types.datastream import ( - DeleteConnectionProfileRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - DeletePrivateConnectionRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import DeleteRouteRequest -from google.cloud.datastream_v1alpha1.types.datastream import DeleteStreamRequest -from google.cloud.datastream_v1alpha1.types.datastream import ( - DiscoverConnectionProfileRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( +from google.cloud.datastream_v1.types.datastream import CreateConnectionProfileRequest +from google.cloud.datastream_v1.types.datastream import CreatePrivateConnectionRequest +from google.cloud.datastream_v1.types.datastream import CreateRouteRequest +from google.cloud.datastream_v1.types.datastream import CreateStreamRequest +from google.cloud.datastream_v1.types.datastream import DeleteConnectionProfileRequest +from google.cloud.datastream_v1.types.datastream import DeletePrivateConnectionRequest +from google.cloud.datastream_v1.types.datastream import DeleteRouteRequest +from google.cloud.datastream_v1.types.datastream import DeleteStreamRequest +from google.cloud.datastream_v1.types.datastream import DiscoverConnectionProfileRequest +from google.cloud.datastream_v1.types.datastream import ( DiscoverConnectionProfileResponse, ) -from google.cloud.datastream_v1alpha1.types.datastream import FetchErrorsRequest -from google.cloud.datastream_v1alpha1.types.datastream import FetchErrorsResponse -from google.cloud.datastream_v1alpha1.types.datastream import FetchStaticIpsRequest -from google.cloud.datastream_v1alpha1.types.datastream import FetchStaticIpsResponse -from google.cloud.datastream_v1alpha1.types.datastream import ( - GetConnectionProfileRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - GetPrivateConnectionRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import GetRouteRequest -from google.cloud.datastream_v1alpha1.types.datastream import GetStreamRequest -from google.cloud.datastream_v1alpha1.types.datastream import ( - ListConnectionProfilesRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - ListConnectionProfilesResponse, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - ListPrivateConnectionsRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import ( - ListPrivateConnectionsResponse, -) -from google.cloud.datastream_v1alpha1.types.datastream import ListRoutesRequest -from google.cloud.datastream_v1alpha1.types.datastream import ListRoutesResponse -from google.cloud.datastream_v1alpha1.types.datastream import ListStreamsRequest -from google.cloud.datastream_v1alpha1.types.datastream import ListStreamsResponse -from google.cloud.datastream_v1alpha1.types.datastream import OperationMetadata -from google.cloud.datastream_v1alpha1.types.datastream import ( - UpdateConnectionProfileRequest, -) -from google.cloud.datastream_v1alpha1.types.datastream import UpdateStreamRequest -from google.cloud.datastream_v1alpha1.types.datastream_resources import AvroFileFormat -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - ConnectionProfile, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - DestinationConfig, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import Error -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( +from google.cloud.datastream_v1.types.datastream import FetchStaticIpsRequest +from google.cloud.datastream_v1.types.datastream import FetchStaticIpsResponse +from google.cloud.datastream_v1.types.datastream import GetConnectionProfileRequest +from google.cloud.datastream_v1.types.datastream import GetPrivateConnectionRequest +from google.cloud.datastream_v1.types.datastream import GetRouteRequest +from google.cloud.datastream_v1.types.datastream import GetStreamObjectRequest +from google.cloud.datastream_v1.types.datastream import GetStreamRequest +from google.cloud.datastream_v1.types.datastream import ListConnectionProfilesRequest +from google.cloud.datastream_v1.types.datastream import ListConnectionProfilesResponse +from google.cloud.datastream_v1.types.datastream import ListPrivateConnectionsRequest +from google.cloud.datastream_v1.types.datastream import ListPrivateConnectionsResponse +from google.cloud.datastream_v1.types.datastream import ListRoutesRequest +from google.cloud.datastream_v1.types.datastream import ListRoutesResponse +from google.cloud.datastream_v1.types.datastream import ListStreamObjectsRequest +from google.cloud.datastream_v1.types.datastream import ListStreamObjectsResponse +from google.cloud.datastream_v1.types.datastream import ListStreamsRequest +from google.cloud.datastream_v1.types.datastream import ListStreamsResponse +from google.cloud.datastream_v1.types.datastream import LookupStreamObjectRequest +from google.cloud.datastream_v1.types.datastream import OperationMetadata +from google.cloud.datastream_v1.types.datastream import StartBackfillJobRequest +from google.cloud.datastream_v1.types.datastream import StartBackfillJobResponse +from google.cloud.datastream_v1.types.datastream import StopBackfillJobRequest +from google.cloud.datastream_v1.types.datastream import StopBackfillJobResponse +from google.cloud.datastream_v1.types.datastream import UpdateConnectionProfileRequest +from google.cloud.datastream_v1.types.datastream import UpdateStreamRequest +from google.cloud.datastream_v1.types.datastream_resources import AvroFileFormat +from google.cloud.datastream_v1.types.datastream_resources import BackfillJob +from google.cloud.datastream_v1.types.datastream_resources import ConnectionProfile +from google.cloud.datastream_v1.types.datastream_resources import DestinationConfig +from google.cloud.datastream_v1.types.datastream_resources import Error +from google.cloud.datastream_v1.types.datastream_resources import ( ForwardSshTunnelConnectivity, ) -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - GcsDestinationConfig, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import GcsProfile -from google.cloud.datastream_v1alpha1.types.datastream_resources import JsonFileFormat -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlColumn -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlDatabase -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlProfile -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlRdbms -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - MysqlSourceConfig, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlSslConfig -from google.cloud.datastream_v1alpha1.types.datastream_resources import MysqlTable -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - NoConnectivitySettings, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import OracleColumn -from google.cloud.datastream_v1alpha1.types.datastream_resources import OracleProfile -from google.cloud.datastream_v1alpha1.types.datastream_resources import OracleRdbms -from google.cloud.datastream_v1alpha1.types.datastream_resources import OracleSchema -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - OracleSourceConfig, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import OracleTable -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - PrivateConnection, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - PrivateConnectivity, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import Route -from google.cloud.datastream_v1alpha1.types.datastream_resources import SourceConfig -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( +from google.cloud.datastream_v1.types.datastream_resources import GcsDestinationConfig +from google.cloud.datastream_v1.types.datastream_resources import GcsProfile +from google.cloud.datastream_v1.types.datastream_resources import JsonFileFormat +from google.cloud.datastream_v1.types.datastream_resources import MysqlColumn +from google.cloud.datastream_v1.types.datastream_resources import MysqlDatabase +from google.cloud.datastream_v1.types.datastream_resources import MysqlProfile +from google.cloud.datastream_v1.types.datastream_resources import MysqlRdbms +from google.cloud.datastream_v1.types.datastream_resources import MysqlSourceConfig +from google.cloud.datastream_v1.types.datastream_resources import MysqlSslConfig +from google.cloud.datastream_v1.types.datastream_resources import MysqlTable +from google.cloud.datastream_v1.types.datastream_resources import OracleColumn +from google.cloud.datastream_v1.types.datastream_resources import OracleProfile +from google.cloud.datastream_v1.types.datastream_resources import OracleRdbms +from google.cloud.datastream_v1.types.datastream_resources import OracleSchema +from google.cloud.datastream_v1.types.datastream_resources import OracleSourceConfig +from google.cloud.datastream_v1.types.datastream_resources import OracleTable +from google.cloud.datastream_v1.types.datastream_resources import PrivateConnection +from google.cloud.datastream_v1.types.datastream_resources import PrivateConnectivity +from google.cloud.datastream_v1.types.datastream_resources import Route +from google.cloud.datastream_v1.types.datastream_resources import SourceConfig +from google.cloud.datastream_v1.types.datastream_resources import SourceObjectIdentifier +from google.cloud.datastream_v1.types.datastream_resources import ( StaticServiceIpConnectivity, ) -from google.cloud.datastream_v1alpha1.types.datastream_resources import Stream -from google.cloud.datastream_v1alpha1.types.datastream_resources import Validation -from google.cloud.datastream_v1alpha1.types.datastream_resources import ( - ValidationMessage, -) -from google.cloud.datastream_v1alpha1.types.datastream_resources import ValidationResult -from google.cloud.datastream_v1alpha1.types.datastream_resources import VpcPeeringConfig -from google.cloud.datastream_v1alpha1.types.datastream_resources import GcsFileFormat -from google.cloud.datastream_v1alpha1.types.datastream_resources import SchemaFileFormat +from google.cloud.datastream_v1.types.datastream_resources import Stream +from google.cloud.datastream_v1.types.datastream_resources import StreamObject +from google.cloud.datastream_v1.types.datastream_resources import Validation +from google.cloud.datastream_v1.types.datastream_resources import ValidationMessage +from google.cloud.datastream_v1.types.datastream_resources import ValidationResult +from google.cloud.datastream_v1.types.datastream_resources import VpcPeeringConfig __all__ = ( "DatastreamClient", @@ -144,13 +108,12 @@ "DeleteStreamRequest", "DiscoverConnectionProfileRequest", "DiscoverConnectionProfileResponse", - "FetchErrorsRequest", - "FetchErrorsResponse", "FetchStaticIpsRequest", "FetchStaticIpsResponse", "GetConnectionProfileRequest", "GetPrivateConnectionRequest", "GetRouteRequest", + "GetStreamObjectRequest", "GetStreamRequest", "ListConnectionProfilesRequest", "ListConnectionProfilesResponse", @@ -158,12 +121,20 @@ "ListPrivateConnectionsResponse", "ListRoutesRequest", "ListRoutesResponse", + "ListStreamObjectsRequest", + "ListStreamObjectsResponse", "ListStreamsRequest", "ListStreamsResponse", + "LookupStreamObjectRequest", "OperationMetadata", + "StartBackfillJobRequest", + "StartBackfillJobResponse", + "StopBackfillJobRequest", + "StopBackfillJobResponse", "UpdateConnectionProfileRequest", "UpdateStreamRequest", "AvroFileFormat", + "BackfillJob", "ConnectionProfile", "DestinationConfig", "Error", @@ -178,7 +149,6 @@ "MysqlSourceConfig", "MysqlSslConfig", "MysqlTable", - "NoConnectivitySettings", "OracleColumn", "OracleProfile", "OracleRdbms", @@ -189,12 +159,12 @@ "PrivateConnectivity", "Route", "SourceConfig", + "SourceObjectIdentifier", "StaticServiceIpConnectivity", "Stream", + "StreamObject", "Validation", "ValidationMessage", "ValidationResult", "VpcPeeringConfig", - "GcsFileFormat", - "SchemaFileFormat", ) diff --git a/google/cloud/datastream_v1/__init__.py b/google/cloud/datastream_v1/__init__.py new file mode 100644 index 0000000..73b1bed --- /dev/null +++ b/google/cloud/datastream_v1/__init__.py @@ -0,0 +1,162 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 .services.datastream import DatastreamClient +from .services.datastream import DatastreamAsyncClient + +from .types.datastream import CreateConnectionProfileRequest +from .types.datastream import CreatePrivateConnectionRequest +from .types.datastream import CreateRouteRequest +from .types.datastream import CreateStreamRequest +from .types.datastream import DeleteConnectionProfileRequest +from .types.datastream import DeletePrivateConnectionRequest +from .types.datastream import DeleteRouteRequest +from .types.datastream import DeleteStreamRequest +from .types.datastream import DiscoverConnectionProfileRequest +from .types.datastream import DiscoverConnectionProfileResponse +from .types.datastream import FetchStaticIpsRequest +from .types.datastream import FetchStaticIpsResponse +from .types.datastream import GetConnectionProfileRequest +from .types.datastream import GetPrivateConnectionRequest +from .types.datastream import GetRouteRequest +from .types.datastream import GetStreamObjectRequest +from .types.datastream import GetStreamRequest +from .types.datastream import ListConnectionProfilesRequest +from .types.datastream import ListConnectionProfilesResponse +from .types.datastream import ListPrivateConnectionsRequest +from .types.datastream import ListPrivateConnectionsResponse +from .types.datastream import ListRoutesRequest +from .types.datastream import ListRoutesResponse +from .types.datastream import ListStreamObjectsRequest +from .types.datastream import ListStreamObjectsResponse +from .types.datastream import ListStreamsRequest +from .types.datastream import ListStreamsResponse +from .types.datastream import LookupStreamObjectRequest +from .types.datastream import OperationMetadata +from .types.datastream import StartBackfillJobRequest +from .types.datastream import StartBackfillJobResponse +from .types.datastream import StopBackfillJobRequest +from .types.datastream import StopBackfillJobResponse +from .types.datastream import UpdateConnectionProfileRequest +from .types.datastream import UpdateStreamRequest +from .types.datastream_resources import AvroFileFormat +from .types.datastream_resources import BackfillJob +from .types.datastream_resources import ConnectionProfile +from .types.datastream_resources import DestinationConfig +from .types.datastream_resources import Error +from .types.datastream_resources import ForwardSshTunnelConnectivity +from .types.datastream_resources import GcsDestinationConfig +from .types.datastream_resources import GcsProfile +from .types.datastream_resources import JsonFileFormat +from .types.datastream_resources import MysqlColumn +from .types.datastream_resources import MysqlDatabase +from .types.datastream_resources import MysqlProfile +from .types.datastream_resources import MysqlRdbms +from .types.datastream_resources import MysqlSourceConfig +from .types.datastream_resources import MysqlSslConfig +from .types.datastream_resources import MysqlTable +from .types.datastream_resources import OracleColumn +from .types.datastream_resources import OracleProfile +from .types.datastream_resources import OracleRdbms +from .types.datastream_resources import OracleSchema +from .types.datastream_resources import OracleSourceConfig +from .types.datastream_resources import OracleTable +from .types.datastream_resources import PrivateConnection +from .types.datastream_resources import PrivateConnectivity +from .types.datastream_resources import Route +from .types.datastream_resources import SourceConfig +from .types.datastream_resources import SourceObjectIdentifier +from .types.datastream_resources import StaticServiceIpConnectivity +from .types.datastream_resources import Stream +from .types.datastream_resources import StreamObject +from .types.datastream_resources import Validation +from .types.datastream_resources import ValidationMessage +from .types.datastream_resources import ValidationResult +from .types.datastream_resources import VpcPeeringConfig + +__all__ = ( + "DatastreamAsyncClient", + "AvroFileFormat", + "BackfillJob", + "ConnectionProfile", + "CreateConnectionProfileRequest", + "CreatePrivateConnectionRequest", + "CreateRouteRequest", + "CreateStreamRequest", + "DatastreamClient", + "DeleteConnectionProfileRequest", + "DeletePrivateConnectionRequest", + "DeleteRouteRequest", + "DeleteStreamRequest", + "DestinationConfig", + "DiscoverConnectionProfileRequest", + "DiscoverConnectionProfileResponse", + "Error", + "FetchStaticIpsRequest", + "FetchStaticIpsResponse", + "ForwardSshTunnelConnectivity", + "GcsDestinationConfig", + "GcsProfile", + "GetConnectionProfileRequest", + "GetPrivateConnectionRequest", + "GetRouteRequest", + "GetStreamObjectRequest", + "GetStreamRequest", + "JsonFileFormat", + "ListConnectionProfilesRequest", + "ListConnectionProfilesResponse", + "ListPrivateConnectionsRequest", + "ListPrivateConnectionsResponse", + "ListRoutesRequest", + "ListRoutesResponse", + "ListStreamObjectsRequest", + "ListStreamObjectsResponse", + "ListStreamsRequest", + "ListStreamsResponse", + "LookupStreamObjectRequest", + "MysqlColumn", + "MysqlDatabase", + "MysqlProfile", + "MysqlRdbms", + "MysqlSourceConfig", + "MysqlSslConfig", + "MysqlTable", + "OperationMetadata", + "OracleColumn", + "OracleProfile", + "OracleRdbms", + "OracleSchema", + "OracleSourceConfig", + "OracleTable", + "PrivateConnection", + "PrivateConnectivity", + "Route", + "SourceConfig", + "SourceObjectIdentifier", + "StartBackfillJobRequest", + "StartBackfillJobResponse", + "StaticServiceIpConnectivity", + "StopBackfillJobRequest", + "StopBackfillJobResponse", + "Stream", + "StreamObject", + "UpdateConnectionProfileRequest", + "UpdateStreamRequest", + "Validation", + "ValidationMessage", + "ValidationResult", + "VpcPeeringConfig", +) diff --git a/google/cloud/datastream_v1/gapic_metadata.json b/google/cloud/datastream_v1/gapic_metadata.json new file mode 100644 index 0000000..b6c5117 --- /dev/null +++ b/google/cloud/datastream_v1/gapic_metadata.json @@ -0,0 +1,273 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.cloud.datastream_v1", + "protoPackage": "google.cloud.datastream.v1", + "schema": "1.0", + "services": { + "Datastream": { + "clients": { + "grpc": { + "libraryClient": "DatastreamClient", + "rpcs": { + "CreateConnectionProfile": { + "methods": [ + "create_connection_profile" + ] + }, + "CreatePrivateConnection": { + "methods": [ + "create_private_connection" + ] + }, + "CreateRoute": { + "methods": [ + "create_route" + ] + }, + "CreateStream": { + "methods": [ + "create_stream" + ] + }, + "DeleteConnectionProfile": { + "methods": [ + "delete_connection_profile" + ] + }, + "DeletePrivateConnection": { + "methods": [ + "delete_private_connection" + ] + }, + "DeleteRoute": { + "methods": [ + "delete_route" + ] + }, + "DeleteStream": { + "methods": [ + "delete_stream" + ] + }, + "DiscoverConnectionProfile": { + "methods": [ + "discover_connection_profile" + ] + }, + "FetchStaticIps": { + "methods": [ + "fetch_static_ips" + ] + }, + "GetConnectionProfile": { + "methods": [ + "get_connection_profile" + ] + }, + "GetPrivateConnection": { + "methods": [ + "get_private_connection" + ] + }, + "GetRoute": { + "methods": [ + "get_route" + ] + }, + "GetStream": { + "methods": [ + "get_stream" + ] + }, + "GetStreamObject": { + "methods": [ + "get_stream_object" + ] + }, + "ListConnectionProfiles": { + "methods": [ + "list_connection_profiles" + ] + }, + "ListPrivateConnections": { + "methods": [ + "list_private_connections" + ] + }, + "ListRoutes": { + "methods": [ + "list_routes" + ] + }, + "ListStreamObjects": { + "methods": [ + "list_stream_objects" + ] + }, + "ListStreams": { + "methods": [ + "list_streams" + ] + }, + "LookupStreamObject": { + "methods": [ + "lookup_stream_object" + ] + }, + "StartBackfillJob": { + "methods": [ + "start_backfill_job" + ] + }, + "StopBackfillJob": { + "methods": [ + "stop_backfill_job" + ] + }, + "UpdateConnectionProfile": { + "methods": [ + "update_connection_profile" + ] + }, + "UpdateStream": { + "methods": [ + "update_stream" + ] + } + } + }, + "grpc-async": { + "libraryClient": "DatastreamAsyncClient", + "rpcs": { + "CreateConnectionProfile": { + "methods": [ + "create_connection_profile" + ] + }, + "CreatePrivateConnection": { + "methods": [ + "create_private_connection" + ] + }, + "CreateRoute": { + "methods": [ + "create_route" + ] + }, + "CreateStream": { + "methods": [ + "create_stream" + ] + }, + "DeleteConnectionProfile": { + "methods": [ + "delete_connection_profile" + ] + }, + "DeletePrivateConnection": { + "methods": [ + "delete_private_connection" + ] + }, + "DeleteRoute": { + "methods": [ + "delete_route" + ] + }, + "DeleteStream": { + "methods": [ + "delete_stream" + ] + }, + "DiscoverConnectionProfile": { + "methods": [ + "discover_connection_profile" + ] + }, + "FetchStaticIps": { + "methods": [ + "fetch_static_ips" + ] + }, + "GetConnectionProfile": { + "methods": [ + "get_connection_profile" + ] + }, + "GetPrivateConnection": { + "methods": [ + "get_private_connection" + ] + }, + "GetRoute": { + "methods": [ + "get_route" + ] + }, + "GetStream": { + "methods": [ + "get_stream" + ] + }, + "GetStreamObject": { + "methods": [ + "get_stream_object" + ] + }, + "ListConnectionProfiles": { + "methods": [ + "list_connection_profiles" + ] + }, + "ListPrivateConnections": { + "methods": [ + "list_private_connections" + ] + }, + "ListRoutes": { + "methods": [ + "list_routes" + ] + }, + "ListStreamObjects": { + "methods": [ + "list_stream_objects" + ] + }, + "ListStreams": { + "methods": [ + "list_streams" + ] + }, + "LookupStreamObject": { + "methods": [ + "lookup_stream_object" + ] + }, + "StartBackfillJob": { + "methods": [ + "start_backfill_job" + ] + }, + "StopBackfillJob": { + "methods": [ + "stop_backfill_job" + ] + }, + "UpdateConnectionProfile": { + "methods": [ + "update_connection_profile" + ] + }, + "UpdateStream": { + "methods": [ + "update_stream" + ] + } + } + } + } + } + } +} diff --git a/google/cloud/datastream_v1/py.typed b/google/cloud/datastream_v1/py.typed new file mode 100644 index 0000000..38ae0fa --- /dev/null +++ b/google/cloud/datastream_v1/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-cloud-datastream package uses inline types. diff --git a/google/cloud/datastream_v1/services/__init__.py b/google/cloud/datastream_v1/services/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/google/cloud/datastream_v1/services/__init__.py @@ -0,0 +1,15 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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/google/cloud/datastream_v1/services/datastream/__init__.py b/google/cloud/datastream_v1/services/datastream/__init__.py new file mode 100644 index 0000000..b2aee97 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/__init__.py @@ -0,0 +1,22 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 DatastreamClient +from .async_client import DatastreamAsyncClient + +__all__ = ( + "DatastreamClient", + "DatastreamAsyncClient", +) diff --git a/google/cloud/datastream_v1/services/datastream/async_client.py b/google/cloud/datastream_v1/services/datastream/async_client.py new file mode 100644 index 0000000..fe0b497 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/async_client.py @@ -0,0 +1,2299 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +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.datastream_v1.services.datastream import pagers +from google.cloud.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +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 DatastreamTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import DatastreamGrpcAsyncIOTransport +from .client import DatastreamClient + + +class DatastreamAsyncClient: + """Datastream service""" + + _client: DatastreamClient + + DEFAULT_ENDPOINT = DatastreamClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = DatastreamClient.DEFAULT_MTLS_ENDPOINT + + connection_profile_path = staticmethod(DatastreamClient.connection_profile_path) + parse_connection_profile_path = staticmethod( + DatastreamClient.parse_connection_profile_path + ) + networks_path = staticmethod(DatastreamClient.networks_path) + parse_networks_path = staticmethod(DatastreamClient.parse_networks_path) + private_connection_path = staticmethod(DatastreamClient.private_connection_path) + parse_private_connection_path = staticmethod( + DatastreamClient.parse_private_connection_path + ) + route_path = staticmethod(DatastreamClient.route_path) + parse_route_path = staticmethod(DatastreamClient.parse_route_path) + stream_path = staticmethod(DatastreamClient.stream_path) + parse_stream_path = staticmethod(DatastreamClient.parse_stream_path) + stream_object_path = staticmethod(DatastreamClient.stream_object_path) + parse_stream_object_path = staticmethod(DatastreamClient.parse_stream_object_path) + common_billing_account_path = staticmethod( + DatastreamClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + DatastreamClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(DatastreamClient.common_folder_path) + parse_common_folder_path = staticmethod(DatastreamClient.parse_common_folder_path) + common_organization_path = staticmethod(DatastreamClient.common_organization_path) + parse_common_organization_path = staticmethod( + DatastreamClient.parse_common_organization_path + ) + common_project_path = staticmethod(DatastreamClient.common_project_path) + parse_common_project_path = staticmethod(DatastreamClient.parse_common_project_path) + common_location_path = staticmethod(DatastreamClient.common_location_path) + parse_common_location_path = staticmethod( + DatastreamClient.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: + DatastreamAsyncClient: The constructed client. + """ + return DatastreamClient.from_service_account_info.__func__(DatastreamAsyncClient, 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: + DatastreamAsyncClient: The constructed client. + """ + return DatastreamClient.from_service_account_file.__func__(DatastreamAsyncClient, 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 variabel 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 DatastreamClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> DatastreamTransport: + """Returns the transport used by the client instance. + + Returns: + DatastreamTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(DatastreamClient).get_transport_class, type(DatastreamClient) + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, DatastreamTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the datastream 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, ~.DatastreamTransport]): 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 = DatastreamClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def list_connection_profiles( + self, + request: Union[datastream.ListConnectionProfilesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListConnectionProfilesAsyncPager: + r"""Use this method to list connection profiles created + in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListConnectionProfilesRequest, dict]): + The request object. Request message for listing + connection profiles. + parent (:class:`str`): + Required. The parent that owns the + collection of connection profiles. + + 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.datastream_v1.services.datastream.pagers.ListConnectionProfilesAsyncPager: + Response message for listing + connection profiles. + 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 = datastream.ListConnectionProfilesRequest(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_connection_profiles, + 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.ListConnectionProfilesAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_connection_profile( + self, + request: Union[datastream.GetConnectionProfileRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.ConnectionProfile: + r"""Use this method to get details about a connection + profile. + + Args: + request (Union[google.cloud.datastream_v1.types.GetConnectionProfileRequest, dict]): + The request object. Request message for getting a + connection profile. + name (:class:`str`): + Required. The name of the connection + profile resource to get. + + 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.datastream_v1.types.ConnectionProfile: + A set of reusable connection + configurations to be used as a source or + destination for a stream. + + """ + # 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 = datastream.GetConnectionProfileRequest(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_connection_profile, + 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 create_connection_profile( + self, + request: Union[datastream.CreateConnectionProfileRequest, dict] = None, + *, + parent: str = None, + connection_profile: datastream_resources.ConnectionProfile = None, + connection_profile_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to create a connection profile in a + project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateConnectionProfileRequest, dict]): + The request object. Request message for creating a + connection profile. + parent (:class:`str`): + Required. The parent that owns the + collection of ConnectionProfiles. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + connection_profile (:class:`google.cloud.datastream_v1.types.ConnectionProfile`): + Required. The connection profile + resource to create. + + This corresponds to the ``connection_profile`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + connection_profile_id (:class:`str`): + Required. The connection profile + identifier. + + This corresponds to the ``connection_profile_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.datastream_v1.types.ConnectionProfile` A set of reusable connection configurations to be used as a source or + destination for a stream. + + """ + # 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, connection_profile, connection_profile_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 = datastream.CreateConnectionProfileRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if connection_profile is not None: + request.connection_profile = connection_profile + if connection_profile_id is not None: + request.connection_profile_id = connection_profile_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_connection_profile, + 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((("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, + datastream_resources.ConnectionProfile, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def update_connection_profile( + self, + request: Union[datastream.UpdateConnectionProfileRequest, dict] = None, + *, + connection_profile: datastream_resources.ConnectionProfile = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to update the parameters of a + connection profile. + + Args: + request (Union[google.cloud.datastream_v1.types.UpdateConnectionProfileRequest, dict]): + The request object. Connection profile update message. + connection_profile (:class:`google.cloud.datastream_v1.types.ConnectionProfile`): + Required. The connection profile to + update. + + This corresponds to the ``connection_profile`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. Field mask is used to specify the fields to be + overwritten in the ConnectionProfile resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten. + + 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.datastream_v1.types.ConnectionProfile` A set of reusable connection configurations to be used as a source or + destination for a stream. + + """ + # 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([connection_profile, 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 = datastream.UpdateConnectionProfileRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if connection_profile is not None: + request.connection_profile = connection_profile + 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_connection_profile, + 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( + (("connection_profile.name", request.connection_profile.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, + datastream_resources.ConnectionProfile, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_connection_profile( + self, + request: Union[datastream.DeleteConnectionProfileRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to delete a connection profile. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteConnectionProfileRequest, dict]): + The request object. Request message for deleting a + connection profile. + name (:class:`str`): + Required. The name of the connection + profile resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 = datastream.DeleteConnectionProfileRequest(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_connection_profile, + 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((("name", request.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, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def discover_connection_profile( + self, + request: Union[datastream.DiscoverConnectionProfileRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.DiscoverConnectionProfileResponse: + r"""Use this method to discover a connection profile. + The discover API call exposes the data objects and + metadata belonging to the profile. Typically, a request + returns children data objects of a parent data object + that's optionally supplied in the request. + + Args: + request (Union[google.cloud.datastream_v1.types.DiscoverConnectionProfileRequest, dict]): + The request object. Request message for 'discover' + ConnectionProfile request. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + 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.datastream_v1.types.DiscoverConnectionProfileResponse: + Response from a discover request. + """ + # Create or coerce a protobuf request object. + request = datastream.DiscoverConnectionProfileRequest(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.discover_connection_profile, + 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,) + + # Done; return the response. + return response + + async def list_streams( + self, + request: Union[datastream.ListStreamsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStreamsAsyncPager: + r"""Use this method to list streams in a project and + location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListStreamsRequest, dict]): + The request object. Request message for listing streams. + parent (:class:`str`): + Required. The parent that owns the + collection of streams. + + 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.datastream_v1.services.datastream.pagers.ListStreamsAsyncPager: + Response message for listing streams. + 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 = datastream.ListStreamsRequest(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_streams, + 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.ListStreamsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_stream( + self, + request: Union[datastream.GetStreamRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.Stream: + r"""Use this method to get details about a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.GetStreamRequest, dict]): + The request object. Request message for getting a + stream. + name (:class:`str`): + Required. The name of the stream + resource to get. + + 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.datastream_v1.types.Stream: + A resource representing streaming + data from a source to a destination. + + """ + # 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 = datastream.GetStreamRequest(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_stream, + 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 create_stream( + self, + request: Union[datastream.CreateStreamRequest, dict] = None, + *, + parent: str = None, + stream: datastream_resources.Stream = None, + stream_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to create a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateStreamRequest, dict]): + The request object. Request message for creating a + stream. + parent (:class:`str`): + Required. The parent that owns the + collection of streams. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + stream (:class:`google.cloud.datastream_v1.types.Stream`): + Required. The stream resource to + create. + + This corresponds to the ``stream`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + stream_id (:class:`str`): + Required. The stream identifier. + This corresponds to the ``stream_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.datastream_v1.types.Stream` A + resource representing streaming data from a source to a + destination. + + """ + # 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, stream, stream_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 = datastream.CreateStreamRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if stream is not None: + request.stream = stream + if stream_id is not None: + request.stream_id = stream_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_stream, + 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((("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, + datastream_resources.Stream, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def update_stream( + self, + request: Union[datastream.UpdateStreamRequest, dict] = None, + *, + stream: datastream_resources.Stream = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to update the configuration of a + stream. + + Args: + request (Union[google.cloud.datastream_v1.types.UpdateStreamRequest, dict]): + The request object. Request message for updating a + stream. + stream (:class:`google.cloud.datastream_v1.types.Stream`): + Required. The stream resource to + update. + + This corresponds to the ``stream`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. Field mask is used to specify the fields to be + overwritten in the stream resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten. + + 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.datastream_v1.types.Stream` A + resource representing streaming data from a source to a + destination. + + """ + # 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([stream, 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 = datastream.UpdateStreamRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if stream is not None: + request.stream = stream + 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_stream, + 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( + (("stream.name", request.stream.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, + datastream_resources.Stream, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_stream( + self, + request: Union[datastream.DeleteStreamRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to delete a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteStreamRequest, dict]): + The request object. Request message for deleting a + stream. + name (:class:`str`): + Required. The name of the stream + resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 = datastream.DeleteStreamRequest(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_stream, + 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((("name", request.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, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def get_stream_object( + self, + request: Union[datastream.GetStreamObjectRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.StreamObject: + r"""Use this method to get details about a stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.GetStreamObjectRequest, dict]): + The request object. Request for fetching a specific + stream object. + name (:class:`str`): + Required. The name of the stream + object resource to get. + + 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.datastream_v1.types.StreamObject: + A specific stream object (e.g a + specific DB table). + + """ + # 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 = datastream.GetStreamObjectRequest(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_stream_object, + 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 lookup_stream_object( + self, + request: Union[datastream.LookupStreamObjectRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.StreamObject: + r"""Use this method to look up a stream object by its + source object identifier. + + Args: + request (Union[google.cloud.datastream_v1.types.LookupStreamObjectRequest, dict]): + The request object. Request for looking up a specific + stream object by its source object identifier. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + 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.datastream_v1.types.StreamObject: + A specific stream object (e.g a + specific DB table). + + """ + # Create or coerce a protobuf request object. + request = datastream.LookupStreamObjectRequest(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.lookup_stream_object, + 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,) + + # Done; return the response. + return response + + async def list_stream_objects( + self, + request: Union[datastream.ListStreamObjectsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStreamObjectsAsyncPager: + r"""Use this method to list the objects of a specific + stream. + + Args: + request (Union[google.cloud.datastream_v1.types.ListStreamObjectsRequest, dict]): + The request object. Request for listing all objects for + a specific stream. + parent (:class:`str`): + Required. The parent stream that owns + the collection of objects. + + 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.datastream_v1.services.datastream.pagers.ListStreamObjectsAsyncPager: + Response containing the objects for a + stream. + 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 = datastream.ListStreamObjectsRequest(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_stream_objects, + 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.ListStreamObjectsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def start_backfill_job( + self, + request: Union[datastream.StartBackfillJobRequest, dict] = None, + *, + object_: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.StartBackfillJobResponse: + r"""Use this method to start a backfill job for the + specified stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.StartBackfillJobRequest, dict]): + The request object. Request for manually initiating a + backfill job for a specific stream object. + object_ (:class:`str`): + Required. The name of the stream + object resource to start a backfill job + for. + + This corresponds to the ``object_`` 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.datastream_v1.types.StartBackfillJobResponse: + Response for manually initiating a + backfill job for a specific stream + object. + + """ + # 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([object_]) + 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 = datastream.StartBackfillJobRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if object_ is not None: + request.object_ = object_ + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.start_backfill_job, + 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((("object", request.object_),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def stop_backfill_job( + self, + request: Union[datastream.StopBackfillJobRequest, dict] = None, + *, + object_: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.StopBackfillJobResponse: + r"""Use this method to stop a backfill job for the + specified stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.StopBackfillJobRequest, dict]): + The request object. Request for manually stopping a + running backfill job for a specific stream object. + object_ (:class:`str`): + Required. The name of the stream + object resource to stop the backfill job + for. + + This corresponds to the ``object_`` 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.datastream_v1.types.StopBackfillJobResponse: + Response for manually stop a backfill + job for a specific stream object. + + """ + # 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([object_]) + 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 = datastream.StopBackfillJobRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if object_ is not None: + request.object_ = object_ + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.stop_backfill_job, + 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((("object", request.object_),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def fetch_static_ips( + self, + request: Union[datastream.FetchStaticIpsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.FetchStaticIpsAsyncPager: + r"""The FetchStaticIps API call exposes the static IP + addresses used by Datastream. + + Args: + request (Union[google.cloud.datastream_v1.types.FetchStaticIpsRequest, dict]): + The request object. Request message for 'FetchStaticIps' + request. + name (:class:`str`): + Required. The resource name for the location for which + static IPs should be returned. Must be in the format + ``projects/*/locations/*``. + + 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.datastream_v1.services.datastream.pagers.FetchStaticIpsAsyncPager: + Response message for a + 'FetchStaticIps' response. + 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([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 = datastream.FetchStaticIpsRequest(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.fetch_static_ips, + 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,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.FetchStaticIpsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_private_connection( + self, + request: Union[datastream.CreatePrivateConnectionRequest, dict] = None, + *, + parent: str = None, + private_connection: datastream_resources.PrivateConnection = None, + private_connection_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to create a private connectivity + configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.CreatePrivateConnectionRequest, dict]): + The request object. Request for creating a private + connection. + parent (:class:`str`): + Required. The parent that owns the + collection of PrivateConnections. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + private_connection (:class:`google.cloud.datastream_v1.types.PrivateConnection`): + Required. The Private Connectivity + resource to create. + + This corresponds to the ``private_connection`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + private_connection_id (:class:`str`): + Required. The private connectivity + identifier. + + This corresponds to the ``private_connection_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.datastream_v1.types.PrivateConnection` The PrivateConnection resource is used to establish private connectivity + between Datastream and a customer's network. + + """ + # 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, private_connection, private_connection_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 = datastream.CreatePrivateConnectionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if private_connection is not None: + request.private_connection = private_connection + if private_connection_id is not None: + request.private_connection_id = private_connection_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_private_connection, + 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((("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, + datastream_resources.PrivateConnection, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def get_private_connection( + self, + request: Union[datastream.GetPrivateConnectionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.PrivateConnection: + r"""Use this method to get details about a private + connectivity configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.GetPrivateConnectionRequest, dict]): + The request object. Request to get a private connection + configuration. + name (:class:`str`): + Required. The name of the private + connectivity configuration to get. + + 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.datastream_v1.types.PrivateConnection: + The PrivateConnection resource is + used to establish private connectivity + between Datastream and a customer's + network. + + """ + # 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 = datastream.GetPrivateConnectionRequest(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_private_connection, + 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 list_private_connections( + self, + request: Union[datastream.ListPrivateConnectionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListPrivateConnectionsAsyncPager: + r"""Use this method to list private connectivity + configurations in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListPrivateConnectionsRequest, dict]): + The request object. Request for listing private + connections. + parent (:class:`str`): + Required. The parent that owns the + collection of private connectivity + configurations. + + 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.datastream_v1.services.datastream.pagers.ListPrivateConnectionsAsyncPager: + Response containing a list of private + connection configurations. + 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 = datastream.ListPrivateConnectionsRequest(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_private_connections, + 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.ListPrivateConnectionsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_private_connection( + self, + request: Union[datastream.DeletePrivateConnectionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to delete a private connectivity + configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.DeletePrivateConnectionRequest, dict]): + The request object. Request to delete a private + connection. + name (:class:`str`): + Required. The name of the private + connectivity configuration 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 = datastream.DeletePrivateConnectionRequest(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_private_connection, + 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((("name", request.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, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def create_route( + self, + request: Union[datastream.CreateRouteRequest, dict] = None, + *, + parent: str = None, + route: datastream_resources.Route = None, + route_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to create a route for a private + connectivity configuration in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateRouteRequest, dict]): + The request object. Route creation request. + parent (:class:`str`): + Required. The parent that owns the + collection of Routes. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + route (:class:`google.cloud.datastream_v1.types.Route`): + Required. The Route resource to + create. + + This corresponds to the ``route`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + route_id (:class:`str`): + Required. The Route identifier. + This corresponds to the ``route_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.datastream_v1.types.Route` The route resource is the child of the private connection resource, + used for defining a route for a private connection. + + """ + # 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, route, route_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 = datastream.CreateRouteRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if route is not None: + request.route = route + if route_id is not None: + request.route_id = route_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_route, + 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((("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, + datastream_resources.Route, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def get_route( + self, + request: Union[datastream.GetRouteRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.Route: + r"""Use this method to get details about a route. + + Args: + request (Union[google.cloud.datastream_v1.types.GetRouteRequest, dict]): + The request object. Route get request. + name (:class:`str`): + Required. The name of the Route + resource to get. + + 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.datastream_v1.types.Route: + The route resource is the child of + the private connection resource, used + for defining a route for a private + connection. + + """ + # 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 = datastream.GetRouteRequest(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_route, + 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 list_routes( + self, + request: Union[datastream.ListRoutesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListRoutesAsyncPager: + r"""Use this method to list routes created for a private + connectivity configuration in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListRoutesRequest, dict]): + The request object. Route list request. + parent (:class:`str`): + Required. The parent that owns the + collection of Routess. + + 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.datastream_v1.services.datastream.pagers.ListRoutesAsyncPager: + Route list response. + 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 = datastream.ListRoutesRequest(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_routes, + 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.ListRoutesAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_route( + self, + request: Union[datastream.DeleteRouteRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Use this method to delete a route. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteRouteRequest, dict]): + The request object. Route deletion request. + name (:class:`str`): + Required. The name of the Route + resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 = datastream.DeleteRouteRequest(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_route, + 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((("name", request.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, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-datastream", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("DatastreamAsyncClient",) diff --git a/google/cloud/datastream_v1/services/datastream/client.py b/google/cloud/datastream_v1/services/datastream/client.py new file mode 100644 index 0000000..3520a34 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/client.py @@ -0,0 +1,2597 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +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.datastream_v1.services.datastream import pagers +from google.cloud.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +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 DatastreamTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import DatastreamGrpcTransport +from .transports.grpc_asyncio import DatastreamGrpcAsyncIOTransport + + +class DatastreamClientMeta(type): + """Metaclass for the Datastream 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[DatastreamTransport]] + _transport_registry["grpc"] = DatastreamGrpcTransport + _transport_registry["grpc_asyncio"] = DatastreamGrpcAsyncIOTransport + + def get_transport_class(cls, label: str = None,) -> Type[DatastreamTransport]: + """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 DatastreamClient(metaclass=DatastreamClientMeta): + """Datastream service""" + + @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 = "datastream.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: + DatastreamClient: 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: + DatastreamClient: 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) -> DatastreamTransport: + """Returns the transport used by the client instance. + + Returns: + DatastreamTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def connection_profile_path( + project: str, location: str, connection_profile: str, + ) -> str: + """Returns a fully-qualified connection_profile string.""" + return "projects/{project}/locations/{location}/connectionProfiles/{connection_profile}".format( + project=project, location=location, connection_profile=connection_profile, + ) + + @staticmethod + def parse_connection_profile_path(path: str) -> Dict[str, str]: + """Parses a connection_profile path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/connectionProfiles/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def networks_path(project: str, network: str,) -> str: + """Returns a fully-qualified networks string.""" + return "projects/{project}/global/networks/{network}".format( + project=project, network=network, + ) + + @staticmethod + def parse_networks_path(path: str) -> Dict[str, str]: + """Parses a networks path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/global/networks/(?P.+?)$", path + ) + return m.groupdict() if m else {} + + @staticmethod + def private_connection_path( + project: str, location: str, private_connection: str, + ) -> str: + """Returns a fully-qualified private_connection string.""" + return "projects/{project}/locations/{location}/privateConnections/{private_connection}".format( + project=project, location=location, private_connection=private_connection, + ) + + @staticmethod + def parse_private_connection_path(path: str) -> Dict[str, str]: + """Parses a private_connection path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/privateConnections/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def route_path( + project: str, location: str, private_connection: str, route: str, + ) -> str: + """Returns a fully-qualified route string.""" + return "projects/{project}/locations/{location}/privateConnections/{private_connection}/routes/{route}".format( + project=project, + location=location, + private_connection=private_connection, + route=route, + ) + + @staticmethod + def parse_route_path(path: str) -> Dict[str, str]: + """Parses a route path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/privateConnections/(?P.+?)/routes/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def stream_path(project: str, location: str, stream: str,) -> str: + """Returns a fully-qualified stream string.""" + return "projects/{project}/locations/{location}/streams/{stream}".format( + project=project, location=location, stream=stream, + ) + + @staticmethod + def parse_stream_path(path: str) -> Dict[str, str]: + """Parses a stream path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/streams/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def stream_object_path( + project: str, location: str, stream: str, object: str, + ) -> str: + """Returns a fully-qualified stream_object string.""" + return "projects/{project}/locations/{location}/streams/{stream}/objects/{object}".format( + project=project, location=location, stream=stream, object=object, + ) + + @staticmethod + def parse_stream_object_path(path: str) -> Dict[str, str]: + """Parses a stream_object path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/streams/(?P.+?)/objects/(?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 variabel 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: Union[str, DatastreamTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the datastream 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, DatastreamTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + 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, DatastreamTransport): + # transport is a DatastreamTransport 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, + ) + + def list_connection_profiles( + self, + request: Union[datastream.ListConnectionProfilesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListConnectionProfilesPager: + r"""Use this method to list connection profiles created + in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListConnectionProfilesRequest, dict]): + The request object. Request message for listing + connection profiles. + parent (str): + Required. The parent that owns the + collection of connection profiles. + + 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.datastream_v1.services.datastream.pagers.ListConnectionProfilesPager: + Response message for listing + connection profiles. + 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 datastream.ListConnectionProfilesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.ListConnectionProfilesRequest): + request = datastream.ListConnectionProfilesRequest(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_connection_profiles] + + # 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.ListConnectionProfilesPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def get_connection_profile( + self, + request: Union[datastream.GetConnectionProfileRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.ConnectionProfile: + r"""Use this method to get details about a connection + profile. + + Args: + request (Union[google.cloud.datastream_v1.types.GetConnectionProfileRequest, dict]): + The request object. Request message for getting a + connection profile. + name (str): + Required. The name of the connection + profile resource to get. + + 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.datastream_v1.types.ConnectionProfile: + A set of reusable connection + configurations to be used as a source or + destination for a stream. + + """ + # 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 datastream.GetConnectionProfileRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.GetConnectionProfileRequest): + request = datastream.GetConnectionProfileRequest(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_connection_profile] + + # 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_connection_profile( + self, + request: Union[datastream.CreateConnectionProfileRequest, dict] = None, + *, + parent: str = None, + connection_profile: datastream_resources.ConnectionProfile = None, + connection_profile_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to create a connection profile in a + project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateConnectionProfileRequest, dict]): + The request object. Request message for creating a + connection profile. + parent (str): + Required. The parent that owns the + collection of ConnectionProfiles. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + connection_profile (google.cloud.datastream_v1.types.ConnectionProfile): + Required. The connection profile + resource to create. + + This corresponds to the ``connection_profile`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + connection_profile_id (str): + Required. The connection profile + identifier. + + This corresponds to the ``connection_profile_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.datastream_v1.types.ConnectionProfile` A set of reusable connection configurations to be used as a source or + destination for a stream. + + """ + # 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, connection_profile, connection_profile_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 datastream.CreateConnectionProfileRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.CreateConnectionProfileRequest): + request = datastream.CreateConnectionProfileRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if connection_profile is not None: + request.connection_profile = connection_profile + if connection_profile_id is not None: + request.connection_profile_id = connection_profile_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_connection_profile + ] + + # 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, + datastream_resources.ConnectionProfile, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def update_connection_profile( + self, + request: Union[datastream.UpdateConnectionProfileRequest, dict] = None, + *, + connection_profile: datastream_resources.ConnectionProfile = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to update the parameters of a + connection profile. + + Args: + request (Union[google.cloud.datastream_v1.types.UpdateConnectionProfileRequest, dict]): + The request object. Connection profile update message. + connection_profile (google.cloud.datastream_v1.types.ConnectionProfile): + Required. The connection profile to + update. + + This corresponds to the ``connection_profile`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the ConnectionProfile resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten. + + 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.datastream_v1.types.ConnectionProfile` A set of reusable connection configurations to be used as a source or + destination for a stream. + + """ + # 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([connection_profile, 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 datastream.UpdateConnectionProfileRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.UpdateConnectionProfileRequest): + request = datastream.UpdateConnectionProfileRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if connection_profile is not None: + request.connection_profile = connection_profile + 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_connection_profile + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("connection_profile.name", request.connection_profile.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, + datastream_resources.ConnectionProfile, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def delete_connection_profile( + self, + request: Union[datastream.DeleteConnectionProfileRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to delete a connection profile. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteConnectionProfileRequest, dict]): + The request object. Request message for deleting a + connection profile. + name (str): + Required. The name of the connection + profile resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 datastream.DeleteConnectionProfileRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.DeleteConnectionProfileRequest): + request = datastream.DeleteConnectionProfileRequest(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_connection_profile + ] + + # 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,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def discover_connection_profile( + self, + request: Union[datastream.DiscoverConnectionProfileRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.DiscoverConnectionProfileResponse: + r"""Use this method to discover a connection profile. + The discover API call exposes the data objects and + metadata belonging to the profile. Typically, a request + returns children data objects of a parent data object + that's optionally supplied in the request. + + Args: + request (Union[google.cloud.datastream_v1.types.DiscoverConnectionProfileRequest, dict]): + The request object. Request message for 'discover' + ConnectionProfile request. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + 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.datastream_v1.types.DiscoverConnectionProfileResponse: + Response from a discover request. + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a datastream.DiscoverConnectionProfileRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.DiscoverConnectionProfileRequest): + request = datastream.DiscoverConnectionProfileRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.discover_connection_profile + ] + + # 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,) + + # Done; return the response. + return response + + def list_streams( + self, + request: Union[datastream.ListStreamsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStreamsPager: + r"""Use this method to list streams in a project and + location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListStreamsRequest, dict]): + The request object. Request message for listing streams. + parent (str): + Required. The parent that owns the + collection of streams. + + 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.datastream_v1.services.datastream.pagers.ListStreamsPager: + Response message for listing streams. + 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 datastream.ListStreamsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.ListStreamsRequest): + request = datastream.ListStreamsRequest(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_streams] + + # 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.ListStreamsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def get_stream( + self, + request: Union[datastream.GetStreamRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.Stream: + r"""Use this method to get details about a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.GetStreamRequest, dict]): + The request object. Request message for getting a + stream. + name (str): + Required. The name of the stream + resource to get. + + 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.datastream_v1.types.Stream: + A resource representing streaming + data from a source to a destination. + + """ + # 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 datastream.GetStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.GetStreamRequest): + request = datastream.GetStreamRequest(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_stream] + + # 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_stream( + self, + request: Union[datastream.CreateStreamRequest, dict] = None, + *, + parent: str = None, + stream: datastream_resources.Stream = None, + stream_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to create a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateStreamRequest, dict]): + The request object. Request message for creating a + stream. + parent (str): + Required. The parent that owns the + collection of streams. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + stream (google.cloud.datastream_v1.types.Stream): + Required. The stream resource to + create. + + This corresponds to the ``stream`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + stream_id (str): + Required. The stream identifier. + This corresponds to the ``stream_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.datastream_v1.types.Stream` A + resource representing streaming data from a source to a + destination. + + """ + # 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, stream, stream_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 datastream.CreateStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.CreateStreamRequest): + request = datastream.CreateStreamRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if stream is not None: + request.stream = stream + if stream_id is not None: + request.stream_id = stream_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_stream] + + # 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, + datastream_resources.Stream, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def update_stream( + self, + request: Union[datastream.UpdateStreamRequest, dict] = None, + *, + stream: datastream_resources.Stream = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to update the configuration of a + stream. + + Args: + request (Union[google.cloud.datastream_v1.types.UpdateStreamRequest, dict]): + The request object. Request message for updating a + stream. + stream (google.cloud.datastream_v1.types.Stream): + Required. The stream resource to + update. + + This corresponds to the ``stream`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the stream resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten. + + 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.datastream_v1.types.Stream` A + resource representing streaming data from a source to a + destination. + + """ + # 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([stream, 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 datastream.UpdateStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.UpdateStreamRequest): + request = datastream.UpdateStreamRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if stream is not None: + request.stream = stream + 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_stream] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("stream.name", request.stream.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, + datastream_resources.Stream, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def delete_stream( + self, + request: Union[datastream.DeleteStreamRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to delete a stream. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteStreamRequest, dict]): + The request object. Request message for deleting a + stream. + name (str): + Required. The name of the stream + resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 datastream.DeleteStreamRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.DeleteStreamRequest): + request = datastream.DeleteStreamRequest(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_stream] + + # 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,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def get_stream_object( + self, + request: Union[datastream.GetStreamObjectRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.StreamObject: + r"""Use this method to get details about a stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.GetStreamObjectRequest, dict]): + The request object. Request for fetching a specific + stream object. + name (str): + Required. The name of the stream + object resource to get. + + 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.datastream_v1.types.StreamObject: + A specific stream object (e.g a + specific DB table). + + """ + # 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 datastream.GetStreamObjectRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.GetStreamObjectRequest): + request = datastream.GetStreamObjectRequest(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_stream_object] + + # 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 lookup_stream_object( + self, + request: Union[datastream.LookupStreamObjectRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.StreamObject: + r"""Use this method to look up a stream object by its + source object identifier. + + Args: + request (Union[google.cloud.datastream_v1.types.LookupStreamObjectRequest, dict]): + The request object. Request for looking up a specific + stream object by its source object identifier. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + 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.datastream_v1.types.StreamObject: + A specific stream object (e.g a + specific DB table). + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a datastream.LookupStreamObjectRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.LookupStreamObjectRequest): + request = datastream.LookupStreamObjectRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.lookup_stream_object] + + # 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,) + + # Done; return the response. + return response + + def list_stream_objects( + self, + request: Union[datastream.ListStreamObjectsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStreamObjectsPager: + r"""Use this method to list the objects of a specific + stream. + + Args: + request (Union[google.cloud.datastream_v1.types.ListStreamObjectsRequest, dict]): + The request object. Request for listing all objects for + a specific stream. + parent (str): + Required. The parent stream that owns + the collection of objects. + + 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.datastream_v1.services.datastream.pagers.ListStreamObjectsPager: + Response containing the objects for a + stream. + 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 datastream.ListStreamObjectsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.ListStreamObjectsRequest): + request = datastream.ListStreamObjectsRequest(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_stream_objects] + + # 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.ListStreamObjectsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def start_backfill_job( + self, + request: Union[datastream.StartBackfillJobRequest, dict] = None, + *, + object_: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.StartBackfillJobResponse: + r"""Use this method to start a backfill job for the + specified stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.StartBackfillJobRequest, dict]): + The request object. Request for manually initiating a + backfill job for a specific stream object. + object_ (str): + Required. The name of the stream + object resource to start a backfill job + for. + + This corresponds to the ``object_`` 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.datastream_v1.types.StartBackfillJobResponse: + Response for manually initiating a + backfill job for a specific stream + object. + + """ + # 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([object_]) + 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 datastream.StartBackfillJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.StartBackfillJobRequest): + request = datastream.StartBackfillJobRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if object_ is not None: + request.object_ = object_ + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.start_backfill_job] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("object", request.object_),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def stop_backfill_job( + self, + request: Union[datastream.StopBackfillJobRequest, dict] = None, + *, + object_: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream.StopBackfillJobResponse: + r"""Use this method to stop a backfill job for the + specified stream object. + + Args: + request (Union[google.cloud.datastream_v1.types.StopBackfillJobRequest, dict]): + The request object. Request for manually stopping a + running backfill job for a specific stream object. + object_ (str): + Required. The name of the stream + object resource to stop the backfill job + for. + + This corresponds to the ``object_`` 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.datastream_v1.types.StopBackfillJobResponse: + Response for manually stop a backfill + job for a specific stream object. + + """ + # 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([object_]) + 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 datastream.StopBackfillJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.StopBackfillJobRequest): + request = datastream.StopBackfillJobRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if object_ is not None: + request.object_ = object_ + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.stop_backfill_job] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("object", request.object_),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def fetch_static_ips( + self, + request: Union[datastream.FetchStaticIpsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.FetchStaticIpsPager: + r"""The FetchStaticIps API call exposes the static IP + addresses used by Datastream. + + Args: + request (Union[google.cloud.datastream_v1.types.FetchStaticIpsRequest, dict]): + The request object. Request message for 'FetchStaticIps' + request. + name (str): + Required. The resource name for the location for which + static IPs should be returned. Must be in the format + ``projects/*/locations/*``. + + 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.datastream_v1.services.datastream.pagers.FetchStaticIpsPager: + Response message for a + 'FetchStaticIps' response. + 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([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 datastream.FetchStaticIpsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.FetchStaticIpsRequest): + request = datastream.FetchStaticIpsRequest(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.fetch_static_ips] + + # 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,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.FetchStaticIpsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def create_private_connection( + self, + request: Union[datastream.CreatePrivateConnectionRequest, dict] = None, + *, + parent: str = None, + private_connection: datastream_resources.PrivateConnection = None, + private_connection_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to create a private connectivity + configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.CreatePrivateConnectionRequest, dict]): + The request object. Request for creating a private + connection. + parent (str): + Required. The parent that owns the + collection of PrivateConnections. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + private_connection (google.cloud.datastream_v1.types.PrivateConnection): + Required. The Private Connectivity + resource to create. + + This corresponds to the ``private_connection`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + private_connection_id (str): + Required. The private connectivity + identifier. + + This corresponds to the ``private_connection_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.datastream_v1.types.PrivateConnection` The PrivateConnection resource is used to establish private connectivity + between Datastream and a customer's network. + + """ + # 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, private_connection, private_connection_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 datastream.CreatePrivateConnectionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.CreatePrivateConnectionRequest): + request = datastream.CreatePrivateConnectionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if private_connection is not None: + request.private_connection = private_connection + if private_connection_id is not None: + request.private_connection_id = private_connection_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_private_connection + ] + + # 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, + datastream_resources.PrivateConnection, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def get_private_connection( + self, + request: Union[datastream.GetPrivateConnectionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.PrivateConnection: + r"""Use this method to get details about a private + connectivity configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.GetPrivateConnectionRequest, dict]): + The request object. Request to get a private connection + configuration. + name (str): + Required. The name of the private + connectivity configuration to get. + + 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.datastream_v1.types.PrivateConnection: + The PrivateConnection resource is + used to establish private connectivity + between Datastream and a customer's + network. + + """ + # 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 datastream.GetPrivateConnectionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.GetPrivateConnectionRequest): + request = datastream.GetPrivateConnectionRequest(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_private_connection] + + # 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_private_connections( + self, + request: Union[datastream.ListPrivateConnectionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListPrivateConnectionsPager: + r"""Use this method to list private connectivity + configurations in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListPrivateConnectionsRequest, dict]): + The request object. Request for listing private + connections. + parent (str): + Required. The parent that owns the + collection of private connectivity + configurations. + + 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.datastream_v1.services.datastream.pagers.ListPrivateConnectionsPager: + Response containing a list of private + connection configurations. + 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 datastream.ListPrivateConnectionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.ListPrivateConnectionsRequest): + request = datastream.ListPrivateConnectionsRequest(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_private_connections] + + # 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.ListPrivateConnectionsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_private_connection( + self, + request: Union[datastream.DeletePrivateConnectionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to delete a private connectivity + configuration. + + Args: + request (Union[google.cloud.datastream_v1.types.DeletePrivateConnectionRequest, dict]): + The request object. Request to delete a private + connection. + name (str): + Required. The name of the private + connectivity configuration 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 datastream.DeletePrivateConnectionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.DeletePrivateConnectionRequest): + request = datastream.DeletePrivateConnectionRequest(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_private_connection + ] + + # 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,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def create_route( + self, + request: Union[datastream.CreateRouteRequest, dict] = None, + *, + parent: str = None, + route: datastream_resources.Route = None, + route_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to create a route for a private + connectivity configuration in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.CreateRouteRequest, dict]): + The request object. Route creation request. + parent (str): + Required. The parent that owns the + collection of Routes. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + route (google.cloud.datastream_v1.types.Route): + Required. The Route resource to + create. + + This corresponds to the ``route`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + route_id (str): + Required. The Route identifier. + This corresponds to the ``route_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.datastream_v1.types.Route` The route resource is the child of the private connection resource, + used for defining a route for a private connection. + + """ + # 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, route, route_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 datastream.CreateRouteRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.CreateRouteRequest): + request = datastream.CreateRouteRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if route is not None: + request.route = route + if route_id is not None: + request.route_id = route_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_route] + + # 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, + datastream_resources.Route, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def get_route( + self, + request: Union[datastream.GetRouteRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> datastream_resources.Route: + r"""Use this method to get details about a route. + + Args: + request (Union[google.cloud.datastream_v1.types.GetRouteRequest, dict]): + The request object. Route get request. + name (str): + Required. The name of the Route + resource to get. + + 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.datastream_v1.types.Route: + The route resource is the child of + the private connection resource, used + for defining a route for a private + connection. + + """ + # 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 datastream.GetRouteRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.GetRouteRequest): + request = datastream.GetRouteRequest(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_route] + + # 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_routes( + self, + request: Union[datastream.ListRoutesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListRoutesPager: + r"""Use this method to list routes created for a private + connectivity configuration in a project and location. + + Args: + request (Union[google.cloud.datastream_v1.types.ListRoutesRequest, dict]): + The request object. Route list request. + parent (str): + Required. The parent that owns the + collection of Routess. + + 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.datastream_v1.services.datastream.pagers.ListRoutesPager: + Route list response. + 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 datastream.ListRoutesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.ListRoutesRequest): + request = datastream.ListRoutesRequest(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_routes] + + # 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.ListRoutesPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_route( + self, + request: Union[datastream.DeleteRouteRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Use this method to delete a route. + + Args: + request (Union[google.cloud.datastream_v1.types.DeleteRouteRequest, dict]): + The request object. Route deletion request. + name (str): + Required. The name of the Route + resource 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. + + 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); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # 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 datastream.DeleteRouteRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, datastream.DeleteRouteRequest): + request = datastream.DeleteRouteRequest(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_route] + + # 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,) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=datastream.OperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + 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() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-datastream", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("DatastreamClient",) diff --git a/google/cloud/datastream_v1/services/datastream/pagers.py b/google/cloud/datastream_v1/services/datastream/pagers.py new file mode 100644 index 0000000..530d1ae --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/pagers.py @@ -0,0 +1,796 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources + + +class ListConnectionProfilesPager: + """A pager for iterating through ``list_connection_profiles`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListConnectionProfilesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``connection_profiles`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListConnectionProfiles`` requests and continue to iterate + through the ``connection_profiles`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListConnectionProfilesResponse` + 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[..., datastream.ListConnectionProfilesResponse], + request: datastream.ListConnectionProfilesRequest, + response: datastream.ListConnectionProfilesResponse, + *, + 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.datastream_v1.types.ListConnectionProfilesRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListConnectionProfilesResponse): + 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 = datastream.ListConnectionProfilesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.ListConnectionProfilesResponse]: + 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[datastream_resources.ConnectionProfile]: + for page in self.pages: + yield from page.connection_profiles + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListConnectionProfilesAsyncPager: + """A pager for iterating through ``list_connection_profiles`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListConnectionProfilesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``connection_profiles`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListConnectionProfiles`` requests and continue to iterate + through the ``connection_profiles`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListConnectionProfilesResponse` + 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[datastream.ListConnectionProfilesResponse]], + request: datastream.ListConnectionProfilesRequest, + response: datastream.ListConnectionProfilesResponse, + *, + 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.datastream_v1.types.ListConnectionProfilesRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListConnectionProfilesResponse): + 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 = datastream.ListConnectionProfilesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.ListConnectionProfilesResponse]: + 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[datastream_resources.ConnectionProfile]: + async def async_generator(): + async for page in self.pages: + for response in page.connection_profiles: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListStreamsPager: + """A pager for iterating through ``list_streams`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListStreamsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``streams`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListStreams`` requests and continue to iterate + through the ``streams`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListStreamsResponse` + 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[..., datastream.ListStreamsResponse], + request: datastream.ListStreamsRequest, + response: datastream.ListStreamsResponse, + *, + 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.datastream_v1.types.ListStreamsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListStreamsResponse): + 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 = datastream.ListStreamsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.ListStreamsResponse]: + 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[datastream_resources.Stream]: + for page in self.pages: + yield from page.streams + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListStreamsAsyncPager: + """A pager for iterating through ``list_streams`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListStreamsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``streams`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListStreams`` requests and continue to iterate + through the ``streams`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListStreamsResponse` + 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[datastream.ListStreamsResponse]], + request: datastream.ListStreamsRequest, + response: datastream.ListStreamsResponse, + *, + 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.datastream_v1.types.ListStreamsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListStreamsResponse): + 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 = datastream.ListStreamsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.ListStreamsResponse]: + 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[datastream_resources.Stream]: + async def async_generator(): + async for page in self.pages: + for response in page.streams: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListStreamObjectsPager: + """A pager for iterating through ``list_stream_objects`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListStreamObjectsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``stream_objects`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListStreamObjects`` requests and continue to iterate + through the ``stream_objects`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListStreamObjectsResponse` + 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[..., datastream.ListStreamObjectsResponse], + request: datastream.ListStreamObjectsRequest, + response: datastream.ListStreamObjectsResponse, + *, + 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.datastream_v1.types.ListStreamObjectsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListStreamObjectsResponse): + 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 = datastream.ListStreamObjectsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.ListStreamObjectsResponse]: + 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[datastream_resources.StreamObject]: + for page in self.pages: + yield from page.stream_objects + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListStreamObjectsAsyncPager: + """A pager for iterating through ``list_stream_objects`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListStreamObjectsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``stream_objects`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListStreamObjects`` requests and continue to iterate + through the ``stream_objects`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListStreamObjectsResponse` + 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[datastream.ListStreamObjectsResponse]], + request: datastream.ListStreamObjectsRequest, + response: datastream.ListStreamObjectsResponse, + *, + 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.datastream_v1.types.ListStreamObjectsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListStreamObjectsResponse): + 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 = datastream.ListStreamObjectsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.ListStreamObjectsResponse]: + 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[datastream_resources.StreamObject]: + async def async_generator(): + async for page in self.pages: + for response in page.stream_objects: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class FetchStaticIpsPager: + """A pager for iterating through ``fetch_static_ips`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.FetchStaticIpsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``static_ips`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``FetchStaticIps`` requests and continue to iterate + through the ``static_ips`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.FetchStaticIpsResponse` + 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[..., datastream.FetchStaticIpsResponse], + request: datastream.FetchStaticIpsRequest, + response: datastream.FetchStaticIpsResponse, + *, + 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.datastream_v1.types.FetchStaticIpsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.FetchStaticIpsResponse): + 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 = datastream.FetchStaticIpsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.FetchStaticIpsResponse]: + 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[str]: + for page in self.pages: + yield from page.static_ips + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class FetchStaticIpsAsyncPager: + """A pager for iterating through ``fetch_static_ips`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.FetchStaticIpsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``static_ips`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``FetchStaticIps`` requests and continue to iterate + through the ``static_ips`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.FetchStaticIpsResponse` + 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[datastream.FetchStaticIpsResponse]], + request: datastream.FetchStaticIpsRequest, + response: datastream.FetchStaticIpsResponse, + *, + 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.datastream_v1.types.FetchStaticIpsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.FetchStaticIpsResponse): + 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 = datastream.FetchStaticIpsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.FetchStaticIpsResponse]: + 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[str]: + async def async_generator(): + async for page in self.pages: + for response in page.static_ips: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListPrivateConnectionsPager: + """A pager for iterating through ``list_private_connections`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListPrivateConnectionsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``private_connections`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListPrivateConnections`` requests and continue to iterate + through the ``private_connections`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListPrivateConnectionsResponse` + 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[..., datastream.ListPrivateConnectionsResponse], + request: datastream.ListPrivateConnectionsRequest, + response: datastream.ListPrivateConnectionsResponse, + *, + 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.datastream_v1.types.ListPrivateConnectionsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListPrivateConnectionsResponse): + 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 = datastream.ListPrivateConnectionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.ListPrivateConnectionsResponse]: + 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[datastream_resources.PrivateConnection]: + for page in self.pages: + yield from page.private_connections + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListPrivateConnectionsAsyncPager: + """A pager for iterating through ``list_private_connections`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListPrivateConnectionsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``private_connections`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListPrivateConnections`` requests and continue to iterate + through the ``private_connections`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListPrivateConnectionsResponse` + 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[datastream.ListPrivateConnectionsResponse]], + request: datastream.ListPrivateConnectionsRequest, + response: datastream.ListPrivateConnectionsResponse, + *, + 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.datastream_v1.types.ListPrivateConnectionsRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListPrivateConnectionsResponse): + 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 = datastream.ListPrivateConnectionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.ListPrivateConnectionsResponse]: + 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[datastream_resources.PrivateConnection]: + async def async_generator(): + async for page in self.pages: + for response in page.private_connections: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListRoutesPager: + """A pager for iterating through ``list_routes`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListRoutesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``routes`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListRoutes`` requests and continue to iterate + through the ``routes`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListRoutesResponse` + 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[..., datastream.ListRoutesResponse], + request: datastream.ListRoutesRequest, + response: datastream.ListRoutesResponse, + *, + 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.datastream_v1.types.ListRoutesRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListRoutesResponse): + 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 = datastream.ListRoutesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[datastream.ListRoutesResponse]: + 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[datastream_resources.Route]: + for page in self.pages: + yield from page.routes + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListRoutesAsyncPager: + """A pager for iterating through ``list_routes`` requests. + + This class thinly wraps an initial + :class:`google.cloud.datastream_v1.types.ListRoutesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``routes`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListRoutes`` requests and continue to iterate + through the ``routes`` field on the + corresponding responses. + + All the usual :class:`google.cloud.datastream_v1.types.ListRoutesResponse` + 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[datastream.ListRoutesResponse]], + request: datastream.ListRoutesRequest, + response: datastream.ListRoutesResponse, + *, + 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.datastream_v1.types.ListRoutesRequest): + The initial request object. + response (google.cloud.datastream_v1.types.ListRoutesResponse): + 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 = datastream.ListRoutesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[datastream.ListRoutesResponse]: + 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[datastream_resources.Route]: + async def async_generator(): + async for page in self.pages: + for response in page.routes: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/datastream_v1/services/datastream/transports/__init__.py b/google/cloud/datastream_v1/services/datastream/transports/__init__.py new file mode 100644 index 0000000..b7d2ccc --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/transports/__init__.py @@ -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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 DatastreamTransport +from .grpc import DatastreamGrpcTransport +from .grpc_asyncio import DatastreamGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[DatastreamTransport]] +_transport_registry["grpc"] = DatastreamGrpcTransport +_transport_registry["grpc_asyncio"] = DatastreamGrpcAsyncIOTransport + +__all__ = ( + "DatastreamTransport", + "DatastreamGrpcTransport", + "DatastreamGrpcAsyncIOTransport", +) diff --git a/google/cloud/datastream_v1/services/datastream/transports/base.py b/google/cloud/datastream_v1/services/datastream/transports/base.py new file mode 100644 index 0000000..a816f54 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/transports/base.py @@ -0,0 +1,500 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 +import pkg_resources + +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.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-datastream", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class DatastreamTransport(abc.ABC): + """Abstract transport class for Datastream.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "datastream.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: 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, + **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. + """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + 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 + ) + + # 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 + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.list_connection_profiles: gapic_v1.method.wrap_method( + self.list_connection_profiles, + default_timeout=None, + client_info=client_info, + ), + self.get_connection_profile: gapic_v1.method.wrap_method( + self.get_connection_profile, + default_timeout=None, + client_info=client_info, + ), + self.create_connection_profile: gapic_v1.method.wrap_method( + self.create_connection_profile, + default_timeout=60.0, + client_info=client_info, + ), + self.update_connection_profile: gapic_v1.method.wrap_method( + self.update_connection_profile, + default_timeout=60.0, + client_info=client_info, + ), + self.delete_connection_profile: gapic_v1.method.wrap_method( + self.delete_connection_profile, + default_timeout=60.0, + client_info=client_info, + ), + self.discover_connection_profile: gapic_v1.method.wrap_method( + self.discover_connection_profile, + default_timeout=None, + client_info=client_info, + ), + self.list_streams: gapic_v1.method.wrap_method( + self.list_streams, default_timeout=None, client_info=client_info, + ), + self.get_stream: gapic_v1.method.wrap_method( + self.get_stream, default_timeout=None, client_info=client_info, + ), + self.create_stream: gapic_v1.method.wrap_method( + self.create_stream, default_timeout=60.0, client_info=client_info, + ), + self.update_stream: gapic_v1.method.wrap_method( + self.update_stream, default_timeout=60.0, client_info=client_info, + ), + self.delete_stream: gapic_v1.method.wrap_method( + self.delete_stream, default_timeout=60.0, client_info=client_info, + ), + self.get_stream_object: gapic_v1.method.wrap_method( + self.get_stream_object, default_timeout=None, client_info=client_info, + ), + self.lookup_stream_object: gapic_v1.method.wrap_method( + self.lookup_stream_object, + default_timeout=None, + client_info=client_info, + ), + self.list_stream_objects: gapic_v1.method.wrap_method( + self.list_stream_objects, default_timeout=None, client_info=client_info, + ), + self.start_backfill_job: gapic_v1.method.wrap_method( + self.start_backfill_job, default_timeout=None, client_info=client_info, + ), + self.stop_backfill_job: gapic_v1.method.wrap_method( + self.stop_backfill_job, default_timeout=None, client_info=client_info, + ), + self.fetch_static_ips: gapic_v1.method.wrap_method( + self.fetch_static_ips, default_timeout=None, client_info=client_info, + ), + self.create_private_connection: gapic_v1.method.wrap_method( + self.create_private_connection, + default_timeout=60.0, + client_info=client_info, + ), + self.get_private_connection: gapic_v1.method.wrap_method( + self.get_private_connection, + default_timeout=None, + client_info=client_info, + ), + self.list_private_connections: gapic_v1.method.wrap_method( + self.list_private_connections, + default_timeout=None, + client_info=client_info, + ), + self.delete_private_connection: gapic_v1.method.wrap_method( + self.delete_private_connection, + default_timeout=60.0, + client_info=client_info, + ), + self.create_route: gapic_v1.method.wrap_method( + self.create_route, default_timeout=60.0, client_info=client_info, + ), + self.get_route: gapic_v1.method.wrap_method( + self.get_route, default_timeout=None, client_info=client_info, + ), + self.list_routes: gapic_v1.method.wrap_method( + self.list_routes, default_timeout=None, client_info=client_info, + ), + self.delete_route: gapic_v1.method.wrap_method( + self.delete_route, default_timeout=60.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_connection_profiles( + self, + ) -> Callable[ + [datastream.ListConnectionProfilesRequest], + Union[ + datastream.ListConnectionProfilesResponse, + Awaitable[datastream.ListConnectionProfilesResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_connection_profile( + self, + ) -> Callable[ + [datastream.GetConnectionProfileRequest], + Union[ + datastream_resources.ConnectionProfile, + Awaitable[datastream_resources.ConnectionProfile], + ], + ]: + raise NotImplementedError() + + @property + def create_connection_profile( + self, + ) -> Callable[ + [datastream.CreateConnectionProfileRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def update_connection_profile( + self, + ) -> Callable[ + [datastream.UpdateConnectionProfileRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_connection_profile( + self, + ) -> Callable[ + [datastream.DeleteConnectionProfileRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def discover_connection_profile( + self, + ) -> Callable[ + [datastream.DiscoverConnectionProfileRequest], + Union[ + datastream.DiscoverConnectionProfileResponse, + Awaitable[datastream.DiscoverConnectionProfileResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_streams( + self, + ) -> Callable[ + [datastream.ListStreamsRequest], + Union[ + datastream.ListStreamsResponse, Awaitable[datastream.ListStreamsResponse] + ], + ]: + raise NotImplementedError() + + @property + def get_stream( + self, + ) -> Callable[ + [datastream.GetStreamRequest], + Union[datastream_resources.Stream, Awaitable[datastream_resources.Stream]], + ]: + raise NotImplementedError() + + @property + def create_stream( + self, + ) -> Callable[ + [datastream.CreateStreamRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def update_stream( + self, + ) -> Callable[ + [datastream.UpdateStreamRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_stream( + self, + ) -> Callable[ + [datastream.DeleteStreamRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_stream_object( + self, + ) -> Callable[ + [datastream.GetStreamObjectRequest], + Union[ + datastream_resources.StreamObject, + Awaitable[datastream_resources.StreamObject], + ], + ]: + raise NotImplementedError() + + @property + def lookup_stream_object( + self, + ) -> Callable[ + [datastream.LookupStreamObjectRequest], + Union[ + datastream_resources.StreamObject, + Awaitable[datastream_resources.StreamObject], + ], + ]: + raise NotImplementedError() + + @property + def list_stream_objects( + self, + ) -> Callable[ + [datastream.ListStreamObjectsRequest], + Union[ + datastream.ListStreamObjectsResponse, + Awaitable[datastream.ListStreamObjectsResponse], + ], + ]: + raise NotImplementedError() + + @property + def start_backfill_job( + self, + ) -> Callable[ + [datastream.StartBackfillJobRequest], + Union[ + datastream.StartBackfillJobResponse, + Awaitable[datastream.StartBackfillJobResponse], + ], + ]: + raise NotImplementedError() + + @property + def stop_backfill_job( + self, + ) -> Callable[ + [datastream.StopBackfillJobRequest], + Union[ + datastream.StopBackfillJobResponse, + Awaitable[datastream.StopBackfillJobResponse], + ], + ]: + raise NotImplementedError() + + @property + def fetch_static_ips( + self, + ) -> Callable[ + [datastream.FetchStaticIpsRequest], + Union[ + datastream.FetchStaticIpsResponse, + Awaitable[datastream.FetchStaticIpsResponse], + ], + ]: + raise NotImplementedError() + + @property + def create_private_connection( + self, + ) -> Callable[ + [datastream.CreatePrivateConnectionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_private_connection( + self, + ) -> Callable[ + [datastream.GetPrivateConnectionRequest], + Union[ + datastream_resources.PrivateConnection, + Awaitable[datastream_resources.PrivateConnection], + ], + ]: + raise NotImplementedError() + + @property + def list_private_connections( + self, + ) -> Callable[ + [datastream.ListPrivateConnectionsRequest], + Union[ + datastream.ListPrivateConnectionsResponse, + Awaitable[datastream.ListPrivateConnectionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_private_connection( + self, + ) -> Callable[ + [datastream.DeletePrivateConnectionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_route( + self, + ) -> Callable[ + [datastream.CreateRouteRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_route( + self, + ) -> Callable[ + [datastream.GetRouteRequest], + Union[datastream_resources.Route, Awaitable[datastream_resources.Route]], + ]: + raise NotImplementedError() + + @property + def list_routes( + self, + ) -> Callable[ + [datastream.ListRoutesRequest], + Union[datastream.ListRoutesResponse, Awaitable[datastream.ListRoutesResponse]], + ]: + raise NotImplementedError() + + @property + def delete_route( + self, + ) -> Callable[ + [datastream.DeleteRouteRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + +__all__ = ("DatastreamTransport",) diff --git a/google/cloud/datastream_v1/services/datastream/transports/grpc.py b/google/cloud/datastream_v1/services/datastream/transports/grpc.py new file mode 100644 index 0000000..7e82de6 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/transports/grpc.py @@ -0,0 +1,959 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +from google.longrunning import operations_pb2 # type: ignore +from .base import DatastreamTransport, DEFAULT_CLIENT_INFO + + +class DatastreamGrpcTransport(DatastreamTransport): + """gRPC backend transport for Datastream. + + Datastream service + + 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 = "datastream.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: 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, + ) -> 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, + ) + + 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 = "datastream.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: 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_connection_profiles( + self, + ) -> Callable[ + [datastream.ListConnectionProfilesRequest], + datastream.ListConnectionProfilesResponse, + ]: + r"""Return a callable for the list connection profiles method over gRPC. + + Use this method to list connection profiles created + in a project and location. + + Returns: + Callable[[~.ListConnectionProfilesRequest], + ~.ListConnectionProfilesResponse]: + 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_connection_profiles" not in self._stubs: + self._stubs["list_connection_profiles"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListConnectionProfiles", + request_serializer=datastream.ListConnectionProfilesRequest.serialize, + response_deserializer=datastream.ListConnectionProfilesResponse.deserialize, + ) + return self._stubs["list_connection_profiles"] + + @property + def get_connection_profile( + self, + ) -> Callable[ + [datastream.GetConnectionProfileRequest], datastream_resources.ConnectionProfile + ]: + r"""Return a callable for the get connection profile method over gRPC. + + Use this method to get details about a connection + profile. + + Returns: + Callable[[~.GetConnectionProfileRequest], + ~.ConnectionProfile]: + 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_connection_profile" not in self._stubs: + self._stubs["get_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetConnectionProfile", + request_serializer=datastream.GetConnectionProfileRequest.serialize, + response_deserializer=datastream_resources.ConnectionProfile.deserialize, + ) + return self._stubs["get_connection_profile"] + + @property + def create_connection_profile( + self, + ) -> Callable[ + [datastream.CreateConnectionProfileRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create connection profile method over gRPC. + + Use this method to create a connection profile in a + project and location. + + Returns: + Callable[[~.CreateConnectionProfileRequest], + ~.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_connection_profile" not in self._stubs: + self._stubs["create_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateConnectionProfile", + request_serializer=datastream.CreateConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_connection_profile"] + + @property + def update_connection_profile( + self, + ) -> Callable[ + [datastream.UpdateConnectionProfileRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update connection profile method over gRPC. + + Use this method to update the parameters of a + connection profile. + + Returns: + Callable[[~.UpdateConnectionProfileRequest], + ~.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_connection_profile" not in self._stubs: + self._stubs["update_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/UpdateConnectionProfile", + request_serializer=datastream.UpdateConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_connection_profile"] + + @property + def delete_connection_profile( + self, + ) -> Callable[ + [datastream.DeleteConnectionProfileRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete connection profile method over gRPC. + + Use this method to delete a connection profile. + + Returns: + Callable[[~.DeleteConnectionProfileRequest], + ~.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 "delete_connection_profile" not in self._stubs: + self._stubs["delete_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteConnectionProfile", + request_serializer=datastream.DeleteConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_connection_profile"] + + @property + def discover_connection_profile( + self, + ) -> Callable[ + [datastream.DiscoverConnectionProfileRequest], + datastream.DiscoverConnectionProfileResponse, + ]: + r"""Return a callable for the discover connection profile method over gRPC. + + Use this method to discover a connection profile. + The discover API call exposes the data objects and + metadata belonging to the profile. Typically, a request + returns children data objects of a parent data object + that's optionally supplied in the request. + + Returns: + Callable[[~.DiscoverConnectionProfileRequest], + ~.DiscoverConnectionProfileResponse]: + 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 "discover_connection_profile" not in self._stubs: + self._stubs["discover_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DiscoverConnectionProfile", + request_serializer=datastream.DiscoverConnectionProfileRequest.serialize, + response_deserializer=datastream.DiscoverConnectionProfileResponse.deserialize, + ) + return self._stubs["discover_connection_profile"] + + @property + def list_streams( + self, + ) -> Callable[[datastream.ListStreamsRequest], datastream.ListStreamsResponse]: + r"""Return a callable for the list streams method over gRPC. + + Use this method to list streams in a project and + location. + + Returns: + Callable[[~.ListStreamsRequest], + ~.ListStreamsResponse]: + 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_streams" not in self._stubs: + self._stubs["list_streams"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListStreams", + request_serializer=datastream.ListStreamsRequest.serialize, + response_deserializer=datastream.ListStreamsResponse.deserialize, + ) + return self._stubs["list_streams"] + + @property + def get_stream( + self, + ) -> Callable[[datastream.GetStreamRequest], datastream_resources.Stream]: + r"""Return a callable for the get stream method over gRPC. + + Use this method to get details about a stream. + + Returns: + Callable[[~.GetStreamRequest], + ~.Stream]: + 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_stream" not in self._stubs: + self._stubs["get_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetStream", + request_serializer=datastream.GetStreamRequest.serialize, + response_deserializer=datastream_resources.Stream.deserialize, + ) + return self._stubs["get_stream"] + + @property + def create_stream( + self, + ) -> Callable[[datastream.CreateStreamRequest], operations_pb2.Operation]: + r"""Return a callable for the create stream method over gRPC. + + Use this method to create a stream. + + Returns: + Callable[[~.CreateStreamRequest], + ~.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_stream" not in self._stubs: + self._stubs["create_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateStream", + request_serializer=datastream.CreateStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_stream"] + + @property + def update_stream( + self, + ) -> Callable[[datastream.UpdateStreamRequest], operations_pb2.Operation]: + r"""Return a callable for the update stream method over gRPC. + + Use this method to update the configuration of a + stream. + + Returns: + Callable[[~.UpdateStreamRequest], + ~.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_stream" not in self._stubs: + self._stubs["update_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/UpdateStream", + request_serializer=datastream.UpdateStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_stream"] + + @property + def delete_stream( + self, + ) -> Callable[[datastream.DeleteStreamRequest], operations_pb2.Operation]: + r"""Return a callable for the delete stream method over gRPC. + + Use this method to delete a stream. + + Returns: + Callable[[~.DeleteStreamRequest], + ~.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 "delete_stream" not in self._stubs: + self._stubs["delete_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteStream", + request_serializer=datastream.DeleteStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_stream"] + + @property + def get_stream_object( + self, + ) -> Callable[ + [datastream.GetStreamObjectRequest], datastream_resources.StreamObject + ]: + r"""Return a callable for the get stream object method over gRPC. + + Use this method to get details about a stream object. + + Returns: + Callable[[~.GetStreamObjectRequest], + ~.StreamObject]: + 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_stream_object" not in self._stubs: + self._stubs["get_stream_object"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetStreamObject", + request_serializer=datastream.GetStreamObjectRequest.serialize, + response_deserializer=datastream_resources.StreamObject.deserialize, + ) + return self._stubs["get_stream_object"] + + @property + def lookup_stream_object( + self, + ) -> Callable[ + [datastream.LookupStreamObjectRequest], datastream_resources.StreamObject + ]: + r"""Return a callable for the lookup stream object method over gRPC. + + Use this method to look up a stream object by its + source object identifier. + + Returns: + Callable[[~.LookupStreamObjectRequest], + ~.StreamObject]: + 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 "lookup_stream_object" not in self._stubs: + self._stubs["lookup_stream_object"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/LookupStreamObject", + request_serializer=datastream.LookupStreamObjectRequest.serialize, + response_deserializer=datastream_resources.StreamObject.deserialize, + ) + return self._stubs["lookup_stream_object"] + + @property + def list_stream_objects( + self, + ) -> Callable[ + [datastream.ListStreamObjectsRequest], datastream.ListStreamObjectsResponse + ]: + r"""Return a callable for the list stream objects method over gRPC. + + Use this method to list the objects of a specific + stream. + + Returns: + Callable[[~.ListStreamObjectsRequest], + ~.ListStreamObjectsResponse]: + 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_stream_objects" not in self._stubs: + self._stubs["list_stream_objects"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListStreamObjects", + request_serializer=datastream.ListStreamObjectsRequest.serialize, + response_deserializer=datastream.ListStreamObjectsResponse.deserialize, + ) + return self._stubs["list_stream_objects"] + + @property + def start_backfill_job( + self, + ) -> Callable[ + [datastream.StartBackfillJobRequest], datastream.StartBackfillJobResponse + ]: + r"""Return a callable for the start backfill job method over gRPC. + + Use this method to start a backfill job for the + specified stream object. + + Returns: + Callable[[~.StartBackfillJobRequest], + ~.StartBackfillJobResponse]: + 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 "start_backfill_job" not in self._stubs: + self._stubs["start_backfill_job"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/StartBackfillJob", + request_serializer=datastream.StartBackfillJobRequest.serialize, + response_deserializer=datastream.StartBackfillJobResponse.deserialize, + ) + return self._stubs["start_backfill_job"] + + @property + def stop_backfill_job( + self, + ) -> Callable[ + [datastream.StopBackfillJobRequest], datastream.StopBackfillJobResponse + ]: + r"""Return a callable for the stop backfill job method over gRPC. + + Use this method to stop a backfill job for the + specified stream object. + + Returns: + Callable[[~.StopBackfillJobRequest], + ~.StopBackfillJobResponse]: + 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 "stop_backfill_job" not in self._stubs: + self._stubs["stop_backfill_job"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/StopBackfillJob", + request_serializer=datastream.StopBackfillJobRequest.serialize, + response_deserializer=datastream.StopBackfillJobResponse.deserialize, + ) + return self._stubs["stop_backfill_job"] + + @property + def fetch_static_ips( + self, + ) -> Callable[ + [datastream.FetchStaticIpsRequest], datastream.FetchStaticIpsResponse + ]: + r"""Return a callable for the fetch static ips method over gRPC. + + The FetchStaticIps API call exposes the static IP + addresses used by Datastream. + + Returns: + Callable[[~.FetchStaticIpsRequest], + ~.FetchStaticIpsResponse]: + 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 "fetch_static_ips" not in self._stubs: + self._stubs["fetch_static_ips"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/FetchStaticIps", + request_serializer=datastream.FetchStaticIpsRequest.serialize, + response_deserializer=datastream.FetchStaticIpsResponse.deserialize, + ) + return self._stubs["fetch_static_ips"] + + @property + def create_private_connection( + self, + ) -> Callable[ + [datastream.CreatePrivateConnectionRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create private connection method over gRPC. + + Use this method to create a private connectivity + configuration. + + Returns: + Callable[[~.CreatePrivateConnectionRequest], + ~.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_private_connection" not in self._stubs: + self._stubs["create_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreatePrivateConnection", + request_serializer=datastream.CreatePrivateConnectionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_private_connection"] + + @property + def get_private_connection( + self, + ) -> Callable[ + [datastream.GetPrivateConnectionRequest], datastream_resources.PrivateConnection + ]: + r"""Return a callable for the get private connection method over gRPC. + + Use this method to get details about a private + connectivity configuration. + + Returns: + Callable[[~.GetPrivateConnectionRequest], + ~.PrivateConnection]: + 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_private_connection" not in self._stubs: + self._stubs["get_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetPrivateConnection", + request_serializer=datastream.GetPrivateConnectionRequest.serialize, + response_deserializer=datastream_resources.PrivateConnection.deserialize, + ) + return self._stubs["get_private_connection"] + + @property + def list_private_connections( + self, + ) -> Callable[ + [datastream.ListPrivateConnectionsRequest], + datastream.ListPrivateConnectionsResponse, + ]: + r"""Return a callable for the list private connections method over gRPC. + + Use this method to list private connectivity + configurations in a project and location. + + Returns: + Callable[[~.ListPrivateConnectionsRequest], + ~.ListPrivateConnectionsResponse]: + 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_private_connections" not in self._stubs: + self._stubs["list_private_connections"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListPrivateConnections", + request_serializer=datastream.ListPrivateConnectionsRequest.serialize, + response_deserializer=datastream.ListPrivateConnectionsResponse.deserialize, + ) + return self._stubs["list_private_connections"] + + @property + def delete_private_connection( + self, + ) -> Callable[ + [datastream.DeletePrivateConnectionRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete private connection method over gRPC. + + Use this method to delete a private connectivity + configuration. + + Returns: + Callable[[~.DeletePrivateConnectionRequest], + ~.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 "delete_private_connection" not in self._stubs: + self._stubs["delete_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeletePrivateConnection", + request_serializer=datastream.DeletePrivateConnectionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_private_connection"] + + @property + def create_route( + self, + ) -> Callable[[datastream.CreateRouteRequest], operations_pb2.Operation]: + r"""Return a callable for the create route method over gRPC. + + Use this method to create a route for a private + connectivity configuration in a project and location. + + Returns: + Callable[[~.CreateRouteRequest], + ~.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_route" not in self._stubs: + self._stubs["create_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateRoute", + request_serializer=datastream.CreateRouteRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_route"] + + @property + def get_route( + self, + ) -> Callable[[datastream.GetRouteRequest], datastream_resources.Route]: + r"""Return a callable for the get route method over gRPC. + + Use this method to get details about a route. + + Returns: + Callable[[~.GetRouteRequest], + ~.Route]: + 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_route" not in self._stubs: + self._stubs["get_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetRoute", + request_serializer=datastream.GetRouteRequest.serialize, + response_deserializer=datastream_resources.Route.deserialize, + ) + return self._stubs["get_route"] + + @property + def list_routes( + self, + ) -> Callable[[datastream.ListRoutesRequest], datastream.ListRoutesResponse]: + r"""Return a callable for the list routes method over gRPC. + + Use this method to list routes created for a private + connectivity configuration in a project and location. + + Returns: + Callable[[~.ListRoutesRequest], + ~.ListRoutesResponse]: + 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_routes" not in self._stubs: + self._stubs["list_routes"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListRoutes", + request_serializer=datastream.ListRoutesRequest.serialize, + response_deserializer=datastream.ListRoutesResponse.deserialize, + ) + return self._stubs["list_routes"] + + @property + def delete_route( + self, + ) -> Callable[[datastream.DeleteRouteRequest], operations_pb2.Operation]: + r"""Return a callable for the delete route method over gRPC. + + Use this method to delete a route. + + Returns: + Callable[[~.DeleteRouteRequest], + ~.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 "delete_route" not in self._stubs: + self._stubs["delete_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteRoute", + request_serializer=datastream.DeleteRouteRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_route"] + + def close(self): + self.grpc_channel.close() + + +__all__ = ("DatastreamGrpcTransport",) diff --git a/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py b/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py new file mode 100644 index 0000000..e292d69 --- /dev/null +++ b/google/cloud/datastream_v1/services/datastream/transports/grpc_asyncio.py @@ -0,0 +1,982 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +from google.longrunning import operations_pb2 # type: ignore +from .base import DatastreamTransport, DEFAULT_CLIENT_INFO +from .grpc import DatastreamGrpcTransport + + +class DatastreamGrpcAsyncIOTransport(DatastreamTransport): + """gRPC AsyncIO backend transport for Datastream. + + Datastream service + + 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 = "datastream.googleapis.com", + credentials: 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 = "datastream.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> 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, + ) + + 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_connection_profiles( + self, + ) -> Callable[ + [datastream.ListConnectionProfilesRequest], + Awaitable[datastream.ListConnectionProfilesResponse], + ]: + r"""Return a callable for the list connection profiles method over gRPC. + + Use this method to list connection profiles created + in a project and location. + + Returns: + Callable[[~.ListConnectionProfilesRequest], + Awaitable[~.ListConnectionProfilesResponse]]: + 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_connection_profiles" not in self._stubs: + self._stubs["list_connection_profiles"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListConnectionProfiles", + request_serializer=datastream.ListConnectionProfilesRequest.serialize, + response_deserializer=datastream.ListConnectionProfilesResponse.deserialize, + ) + return self._stubs["list_connection_profiles"] + + @property + def get_connection_profile( + self, + ) -> Callable[ + [datastream.GetConnectionProfileRequest], + Awaitable[datastream_resources.ConnectionProfile], + ]: + r"""Return a callable for the get connection profile method over gRPC. + + Use this method to get details about a connection + profile. + + Returns: + Callable[[~.GetConnectionProfileRequest], + Awaitable[~.ConnectionProfile]]: + 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_connection_profile" not in self._stubs: + self._stubs["get_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetConnectionProfile", + request_serializer=datastream.GetConnectionProfileRequest.serialize, + response_deserializer=datastream_resources.ConnectionProfile.deserialize, + ) + return self._stubs["get_connection_profile"] + + @property + def create_connection_profile( + self, + ) -> Callable[ + [datastream.CreateConnectionProfileRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the create connection profile method over gRPC. + + Use this method to create a connection profile in a + project and location. + + Returns: + Callable[[~.CreateConnectionProfileRequest], + 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_connection_profile" not in self._stubs: + self._stubs["create_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateConnectionProfile", + request_serializer=datastream.CreateConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_connection_profile"] + + @property + def update_connection_profile( + self, + ) -> Callable[ + [datastream.UpdateConnectionProfileRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the update connection profile method over gRPC. + + Use this method to update the parameters of a + connection profile. + + Returns: + Callable[[~.UpdateConnectionProfileRequest], + 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_connection_profile" not in self._stubs: + self._stubs["update_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/UpdateConnectionProfile", + request_serializer=datastream.UpdateConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_connection_profile"] + + @property + def delete_connection_profile( + self, + ) -> Callable[ + [datastream.DeleteConnectionProfileRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete connection profile method over gRPC. + + Use this method to delete a connection profile. + + Returns: + Callable[[~.DeleteConnectionProfileRequest], + 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 "delete_connection_profile" not in self._stubs: + self._stubs["delete_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteConnectionProfile", + request_serializer=datastream.DeleteConnectionProfileRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_connection_profile"] + + @property + def discover_connection_profile( + self, + ) -> Callable[ + [datastream.DiscoverConnectionProfileRequest], + Awaitable[datastream.DiscoverConnectionProfileResponse], + ]: + r"""Return a callable for the discover connection profile method over gRPC. + + Use this method to discover a connection profile. + The discover API call exposes the data objects and + metadata belonging to the profile. Typically, a request + returns children data objects of a parent data object + that's optionally supplied in the request. + + Returns: + Callable[[~.DiscoverConnectionProfileRequest], + Awaitable[~.DiscoverConnectionProfileResponse]]: + 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 "discover_connection_profile" not in self._stubs: + self._stubs["discover_connection_profile"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DiscoverConnectionProfile", + request_serializer=datastream.DiscoverConnectionProfileRequest.serialize, + response_deserializer=datastream.DiscoverConnectionProfileResponse.deserialize, + ) + return self._stubs["discover_connection_profile"] + + @property + def list_streams( + self, + ) -> Callable[ + [datastream.ListStreamsRequest], Awaitable[datastream.ListStreamsResponse] + ]: + r"""Return a callable for the list streams method over gRPC. + + Use this method to list streams in a project and + location. + + Returns: + Callable[[~.ListStreamsRequest], + Awaitable[~.ListStreamsResponse]]: + 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_streams" not in self._stubs: + self._stubs["list_streams"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListStreams", + request_serializer=datastream.ListStreamsRequest.serialize, + response_deserializer=datastream.ListStreamsResponse.deserialize, + ) + return self._stubs["list_streams"] + + @property + def get_stream( + self, + ) -> Callable[ + [datastream.GetStreamRequest], Awaitable[datastream_resources.Stream] + ]: + r"""Return a callable for the get stream method over gRPC. + + Use this method to get details about a stream. + + Returns: + Callable[[~.GetStreamRequest], + Awaitable[~.Stream]]: + 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_stream" not in self._stubs: + self._stubs["get_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetStream", + request_serializer=datastream.GetStreamRequest.serialize, + response_deserializer=datastream_resources.Stream.deserialize, + ) + return self._stubs["get_stream"] + + @property + def create_stream( + self, + ) -> Callable[ + [datastream.CreateStreamRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the create stream method over gRPC. + + Use this method to create a stream. + + Returns: + Callable[[~.CreateStreamRequest], + 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_stream" not in self._stubs: + self._stubs["create_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateStream", + request_serializer=datastream.CreateStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_stream"] + + @property + def update_stream( + self, + ) -> Callable[ + [datastream.UpdateStreamRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the update stream method over gRPC. + + Use this method to update the configuration of a + stream. + + Returns: + Callable[[~.UpdateStreamRequest], + 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_stream" not in self._stubs: + self._stubs["update_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/UpdateStream", + request_serializer=datastream.UpdateStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_stream"] + + @property + def delete_stream( + self, + ) -> Callable[ + [datastream.DeleteStreamRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete stream method over gRPC. + + Use this method to delete a stream. + + Returns: + Callable[[~.DeleteStreamRequest], + 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 "delete_stream" not in self._stubs: + self._stubs["delete_stream"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteStream", + request_serializer=datastream.DeleteStreamRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_stream"] + + @property + def get_stream_object( + self, + ) -> Callable[ + [datastream.GetStreamObjectRequest], + Awaitable[datastream_resources.StreamObject], + ]: + r"""Return a callable for the get stream object method over gRPC. + + Use this method to get details about a stream object. + + Returns: + Callable[[~.GetStreamObjectRequest], + Awaitable[~.StreamObject]]: + 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_stream_object" not in self._stubs: + self._stubs["get_stream_object"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetStreamObject", + request_serializer=datastream.GetStreamObjectRequest.serialize, + response_deserializer=datastream_resources.StreamObject.deserialize, + ) + return self._stubs["get_stream_object"] + + @property + def lookup_stream_object( + self, + ) -> Callable[ + [datastream.LookupStreamObjectRequest], + Awaitable[datastream_resources.StreamObject], + ]: + r"""Return a callable for the lookup stream object method over gRPC. + + Use this method to look up a stream object by its + source object identifier. + + Returns: + Callable[[~.LookupStreamObjectRequest], + Awaitable[~.StreamObject]]: + 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 "lookup_stream_object" not in self._stubs: + self._stubs["lookup_stream_object"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/LookupStreamObject", + request_serializer=datastream.LookupStreamObjectRequest.serialize, + response_deserializer=datastream_resources.StreamObject.deserialize, + ) + return self._stubs["lookup_stream_object"] + + @property + def list_stream_objects( + self, + ) -> Callable[ + [datastream.ListStreamObjectsRequest], + Awaitable[datastream.ListStreamObjectsResponse], + ]: + r"""Return a callable for the list stream objects method over gRPC. + + Use this method to list the objects of a specific + stream. + + Returns: + Callable[[~.ListStreamObjectsRequest], + Awaitable[~.ListStreamObjectsResponse]]: + 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_stream_objects" not in self._stubs: + self._stubs["list_stream_objects"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListStreamObjects", + request_serializer=datastream.ListStreamObjectsRequest.serialize, + response_deserializer=datastream.ListStreamObjectsResponse.deserialize, + ) + return self._stubs["list_stream_objects"] + + @property + def start_backfill_job( + self, + ) -> Callable[ + [datastream.StartBackfillJobRequest], + Awaitable[datastream.StartBackfillJobResponse], + ]: + r"""Return a callable for the start backfill job method over gRPC. + + Use this method to start a backfill job for the + specified stream object. + + Returns: + Callable[[~.StartBackfillJobRequest], + Awaitable[~.StartBackfillJobResponse]]: + 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 "start_backfill_job" not in self._stubs: + self._stubs["start_backfill_job"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/StartBackfillJob", + request_serializer=datastream.StartBackfillJobRequest.serialize, + response_deserializer=datastream.StartBackfillJobResponse.deserialize, + ) + return self._stubs["start_backfill_job"] + + @property + def stop_backfill_job( + self, + ) -> Callable[ + [datastream.StopBackfillJobRequest], + Awaitable[datastream.StopBackfillJobResponse], + ]: + r"""Return a callable for the stop backfill job method over gRPC. + + Use this method to stop a backfill job for the + specified stream object. + + Returns: + Callable[[~.StopBackfillJobRequest], + Awaitable[~.StopBackfillJobResponse]]: + 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 "stop_backfill_job" not in self._stubs: + self._stubs["stop_backfill_job"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/StopBackfillJob", + request_serializer=datastream.StopBackfillJobRequest.serialize, + response_deserializer=datastream.StopBackfillJobResponse.deserialize, + ) + return self._stubs["stop_backfill_job"] + + @property + def fetch_static_ips( + self, + ) -> Callable[ + [datastream.FetchStaticIpsRequest], Awaitable[datastream.FetchStaticIpsResponse] + ]: + r"""Return a callable for the fetch static ips method over gRPC. + + The FetchStaticIps API call exposes the static IP + addresses used by Datastream. + + Returns: + Callable[[~.FetchStaticIpsRequest], + Awaitable[~.FetchStaticIpsResponse]]: + 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 "fetch_static_ips" not in self._stubs: + self._stubs["fetch_static_ips"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/FetchStaticIps", + request_serializer=datastream.FetchStaticIpsRequest.serialize, + response_deserializer=datastream.FetchStaticIpsResponse.deserialize, + ) + return self._stubs["fetch_static_ips"] + + @property + def create_private_connection( + self, + ) -> Callable[ + [datastream.CreatePrivateConnectionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the create private connection method over gRPC. + + Use this method to create a private connectivity + configuration. + + Returns: + Callable[[~.CreatePrivateConnectionRequest], + 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_private_connection" not in self._stubs: + self._stubs["create_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreatePrivateConnection", + request_serializer=datastream.CreatePrivateConnectionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_private_connection"] + + @property + def get_private_connection( + self, + ) -> Callable[ + [datastream.GetPrivateConnectionRequest], + Awaitable[datastream_resources.PrivateConnection], + ]: + r"""Return a callable for the get private connection method over gRPC. + + Use this method to get details about a private + connectivity configuration. + + Returns: + Callable[[~.GetPrivateConnectionRequest], + Awaitable[~.PrivateConnection]]: + 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_private_connection" not in self._stubs: + self._stubs["get_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetPrivateConnection", + request_serializer=datastream.GetPrivateConnectionRequest.serialize, + response_deserializer=datastream_resources.PrivateConnection.deserialize, + ) + return self._stubs["get_private_connection"] + + @property + def list_private_connections( + self, + ) -> Callable[ + [datastream.ListPrivateConnectionsRequest], + Awaitable[datastream.ListPrivateConnectionsResponse], + ]: + r"""Return a callable for the list private connections method over gRPC. + + Use this method to list private connectivity + configurations in a project and location. + + Returns: + Callable[[~.ListPrivateConnectionsRequest], + Awaitable[~.ListPrivateConnectionsResponse]]: + 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_private_connections" not in self._stubs: + self._stubs["list_private_connections"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListPrivateConnections", + request_serializer=datastream.ListPrivateConnectionsRequest.serialize, + response_deserializer=datastream.ListPrivateConnectionsResponse.deserialize, + ) + return self._stubs["list_private_connections"] + + @property + def delete_private_connection( + self, + ) -> Callable[ + [datastream.DeletePrivateConnectionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete private connection method over gRPC. + + Use this method to delete a private connectivity + configuration. + + Returns: + Callable[[~.DeletePrivateConnectionRequest], + 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 "delete_private_connection" not in self._stubs: + self._stubs["delete_private_connection"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeletePrivateConnection", + request_serializer=datastream.DeletePrivateConnectionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_private_connection"] + + @property + def create_route( + self, + ) -> Callable[[datastream.CreateRouteRequest], Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the create route method over gRPC. + + Use this method to create a route for a private + connectivity configuration in a project and location. + + Returns: + Callable[[~.CreateRouteRequest], + 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_route" not in self._stubs: + self._stubs["create_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/CreateRoute", + request_serializer=datastream.CreateRouteRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_route"] + + @property + def get_route( + self, + ) -> Callable[[datastream.GetRouteRequest], Awaitable[datastream_resources.Route]]: + r"""Return a callable for the get route method over gRPC. + + Use this method to get details about a route. + + Returns: + Callable[[~.GetRouteRequest], + Awaitable[~.Route]]: + 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_route" not in self._stubs: + self._stubs["get_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/GetRoute", + request_serializer=datastream.GetRouteRequest.serialize, + response_deserializer=datastream_resources.Route.deserialize, + ) + return self._stubs["get_route"] + + @property + def list_routes( + self, + ) -> Callable[ + [datastream.ListRoutesRequest], Awaitable[datastream.ListRoutesResponse] + ]: + r"""Return a callable for the list routes method over gRPC. + + Use this method to list routes created for a private + connectivity configuration in a project and location. + + Returns: + Callable[[~.ListRoutesRequest], + Awaitable[~.ListRoutesResponse]]: + 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_routes" not in self._stubs: + self._stubs["list_routes"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/ListRoutes", + request_serializer=datastream.ListRoutesRequest.serialize, + response_deserializer=datastream.ListRoutesResponse.deserialize, + ) + return self._stubs["list_routes"] + + @property + def delete_route( + self, + ) -> Callable[[datastream.DeleteRouteRequest], Awaitable[operations_pb2.Operation]]: + r"""Return a callable for the delete route method over gRPC. + + Use this method to delete a route. + + Returns: + Callable[[~.DeleteRouteRequest], + 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 "delete_route" not in self._stubs: + self._stubs["delete_route"] = self.grpc_channel.unary_unary( + "/google.cloud.datastream.v1.Datastream/DeleteRoute", + request_serializer=datastream.DeleteRouteRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_route"] + + def close(self): + return self.grpc_channel.close() + + +__all__ = ("DatastreamGrpcAsyncIOTransport",) diff --git a/google/cloud/datastream_v1/types/__init__.py b/google/cloud/datastream_v1/types/__init__.py new file mode 100644 index 0000000..1aafa21 --- /dev/null +++ b/google/cloud/datastream_v1/types/__init__.py @@ -0,0 +1,160 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 .datastream import ( + CreateConnectionProfileRequest, + CreatePrivateConnectionRequest, + CreateRouteRequest, + CreateStreamRequest, + DeleteConnectionProfileRequest, + DeletePrivateConnectionRequest, + DeleteRouteRequest, + DeleteStreamRequest, + DiscoverConnectionProfileRequest, + DiscoverConnectionProfileResponse, + FetchStaticIpsRequest, + FetchStaticIpsResponse, + GetConnectionProfileRequest, + GetPrivateConnectionRequest, + GetRouteRequest, + GetStreamObjectRequest, + GetStreamRequest, + ListConnectionProfilesRequest, + ListConnectionProfilesResponse, + ListPrivateConnectionsRequest, + ListPrivateConnectionsResponse, + ListRoutesRequest, + ListRoutesResponse, + ListStreamObjectsRequest, + ListStreamObjectsResponse, + ListStreamsRequest, + ListStreamsResponse, + LookupStreamObjectRequest, + OperationMetadata, + StartBackfillJobRequest, + StartBackfillJobResponse, + StopBackfillJobRequest, + StopBackfillJobResponse, + UpdateConnectionProfileRequest, + UpdateStreamRequest, +) +from .datastream_resources import ( + AvroFileFormat, + BackfillJob, + ConnectionProfile, + DestinationConfig, + Error, + ForwardSshTunnelConnectivity, + GcsDestinationConfig, + GcsProfile, + JsonFileFormat, + MysqlColumn, + MysqlDatabase, + MysqlProfile, + MysqlRdbms, + MysqlSourceConfig, + MysqlSslConfig, + MysqlTable, + OracleColumn, + OracleProfile, + OracleRdbms, + OracleSchema, + OracleSourceConfig, + OracleTable, + PrivateConnection, + PrivateConnectivity, + Route, + SourceConfig, + SourceObjectIdentifier, + StaticServiceIpConnectivity, + Stream, + StreamObject, + Validation, + ValidationMessage, + ValidationResult, + VpcPeeringConfig, +) + +__all__ = ( + "CreateConnectionProfileRequest", + "CreatePrivateConnectionRequest", + "CreateRouteRequest", + "CreateStreamRequest", + "DeleteConnectionProfileRequest", + "DeletePrivateConnectionRequest", + "DeleteRouteRequest", + "DeleteStreamRequest", + "DiscoverConnectionProfileRequest", + "DiscoverConnectionProfileResponse", + "FetchStaticIpsRequest", + "FetchStaticIpsResponse", + "GetConnectionProfileRequest", + "GetPrivateConnectionRequest", + "GetRouteRequest", + "GetStreamObjectRequest", + "GetStreamRequest", + "ListConnectionProfilesRequest", + "ListConnectionProfilesResponse", + "ListPrivateConnectionsRequest", + "ListPrivateConnectionsResponse", + "ListRoutesRequest", + "ListRoutesResponse", + "ListStreamObjectsRequest", + "ListStreamObjectsResponse", + "ListStreamsRequest", + "ListStreamsResponse", + "LookupStreamObjectRequest", + "OperationMetadata", + "StartBackfillJobRequest", + "StartBackfillJobResponse", + "StopBackfillJobRequest", + "StopBackfillJobResponse", + "UpdateConnectionProfileRequest", + "UpdateStreamRequest", + "AvroFileFormat", + "BackfillJob", + "ConnectionProfile", + "DestinationConfig", + "Error", + "ForwardSshTunnelConnectivity", + "GcsDestinationConfig", + "GcsProfile", + "JsonFileFormat", + "MysqlColumn", + "MysqlDatabase", + "MysqlProfile", + "MysqlRdbms", + "MysqlSourceConfig", + "MysqlSslConfig", + "MysqlTable", + "OracleColumn", + "OracleProfile", + "OracleRdbms", + "OracleSchema", + "OracleSourceConfig", + "OracleTable", + "PrivateConnection", + "PrivateConnectivity", + "Route", + "SourceConfig", + "SourceObjectIdentifier", + "StaticServiceIpConnectivity", + "Stream", + "StreamObject", + "Validation", + "ValidationMessage", + "ValidationResult", + "VpcPeeringConfig", +) diff --git a/google/cloud/datastream_v1/types/datastream.py b/google/cloud/datastream_v1/types/datastream.py new file mode 100644 index 0000000..10e6772 --- /dev/null +++ b/google/cloud/datastream_v1/types/datastream.py @@ -0,0 +1,1072 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 proto # type: ignore + +from google.cloud.datastream_v1.types import datastream_resources +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.datastream.v1", + manifest={ + "DiscoverConnectionProfileRequest", + "DiscoverConnectionProfileResponse", + "FetchStaticIpsRequest", + "FetchStaticIpsResponse", + "ListConnectionProfilesRequest", + "ListConnectionProfilesResponse", + "GetConnectionProfileRequest", + "CreateConnectionProfileRequest", + "UpdateConnectionProfileRequest", + "DeleteConnectionProfileRequest", + "ListStreamsRequest", + "ListStreamsResponse", + "GetStreamRequest", + "CreateStreamRequest", + "UpdateStreamRequest", + "DeleteStreamRequest", + "GetStreamObjectRequest", + "LookupStreamObjectRequest", + "StartBackfillJobRequest", + "StartBackfillJobResponse", + "StopBackfillJobRequest", + "StopBackfillJobResponse", + "ListStreamObjectsRequest", + "ListStreamObjectsResponse", + "OperationMetadata", + "CreatePrivateConnectionRequest", + "ListPrivateConnectionsRequest", + "ListPrivateConnectionsResponse", + "DeletePrivateConnectionRequest", + "GetPrivateConnectionRequest", + "CreateRouteRequest", + "ListRoutesRequest", + "ListRoutesResponse", + "DeleteRouteRequest", + "GetRouteRequest", + }, +) + + +class DiscoverConnectionProfileRequest(proto.Message): + r"""Request message for 'discover' ConnectionProfile request. + + 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: + parent (str): + Required. The parent resource of the connection profile + type. Must be in the format ``projects/*/locations/*``. + connection_profile (google.cloud.datastream_v1.types.ConnectionProfile): + An ad-hoc connection profile configuration. + + This field is a member of `oneof`_ ``target``. + connection_profile_name (str): + A reference to an existing connection + profile. + + This field is a member of `oneof`_ ``target``. + full_hierarchy (bool): + Whether to retrieve the full hierarchy of + data objects (TRUE) or only the current level + (FALSE). + + This field is a member of `oneof`_ ``hierarchy``. + hierarchy_depth (int): + The number of hierarchy levels below the + current level to be retrieved. + + This field is a member of `oneof`_ ``hierarchy``. + oracle_rdbms (google.cloud.datastream_v1.types.OracleRdbms): + Oracle RDBMS to enrich with child data + objects and metadata. + + This field is a member of `oneof`_ ``data_object``. + mysql_rdbms (google.cloud.datastream_v1.types.MysqlRdbms): + MySQL RDBMS to enrich with child data objects + and metadata. + + This field is a member of `oneof`_ ``data_object``. + """ + + parent = proto.Field(proto.STRING, number=1,) + connection_profile = proto.Field( + proto.MESSAGE, + number=200, + oneof="target", + message=datastream_resources.ConnectionProfile, + ) + connection_profile_name = proto.Field(proto.STRING, number=201, oneof="target",) + full_hierarchy = proto.Field(proto.BOOL, number=3, oneof="hierarchy",) + hierarchy_depth = proto.Field(proto.INT32, number=4, oneof="hierarchy",) + oracle_rdbms = proto.Field( + proto.MESSAGE, + number=100, + oneof="data_object", + message=datastream_resources.OracleRdbms, + ) + mysql_rdbms = proto.Field( + proto.MESSAGE, + number=101, + oneof="data_object", + message=datastream_resources.MysqlRdbms, + ) + + +class DiscoverConnectionProfileResponse(proto.Message): + r"""Response from a discover request. + + 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: + oracle_rdbms (google.cloud.datastream_v1.types.OracleRdbms): + Enriched Oracle RDBMS object. + + This field is a member of `oneof`_ ``data_object``. + mysql_rdbms (google.cloud.datastream_v1.types.MysqlRdbms): + Enriched MySQL RDBMS object. + + This field is a member of `oneof`_ ``data_object``. + """ + + oracle_rdbms = proto.Field( + proto.MESSAGE, + number=100, + oneof="data_object", + message=datastream_resources.OracleRdbms, + ) + mysql_rdbms = proto.Field( + proto.MESSAGE, + number=101, + oneof="data_object", + message=datastream_resources.MysqlRdbms, + ) + + +class FetchStaticIpsRequest(proto.Message): + r"""Request message for 'FetchStaticIps' request. + + Attributes: + name (str): + Required. The resource name for the location for which + static IPs should be returned. Must be in the format + ``projects/*/locations/*``. + page_size (int): + Maximum number of Ips to return, will likely + not be specified. + page_token (str): + A page token, received from a previous ``ListStaticIps`` + call. will likely not be specified. + """ + + name = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class FetchStaticIpsResponse(proto.Message): + r"""Response message for a 'FetchStaticIps' response. + + Attributes: + static_ips (Sequence[str]): + list of static ips by account + next_page_token (str): + A token that can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + """ + + @property + def raw_page(self): + return self + + static_ips = proto.RepeatedField(proto.STRING, number=1,) + next_page_token = proto.Field(proto.STRING, number=2,) + + +class ListConnectionProfilesRequest(proto.Message): + r"""Request message for listing connection profiles. + + Attributes: + parent (str): + Required. The parent that owns the collection + of connection profiles. + page_size (int): + Maximum number of connection profiles to + return. If unspecified, at most 50 connection + profiles will be returned. The maximum value is + 1000; values above 1000 will be coerced to 1000. + page_token (str): + Page token received from a previous + ``ListConnectionProfiles`` call. Provide this to retrieve + the subsequent page. + + When paginating, all other parameters provided to + ``ListConnectionProfiles`` must match the call that provided + the page token. + filter (str): + Filter request. + order_by (str): + Order by fields for the result. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) + + +class ListConnectionProfilesResponse(proto.Message): + r"""Response message for listing connection profiles. + + Attributes: + connection_profiles (Sequence[google.cloud.datastream_v1.types.ConnectionProfile]): + List of connection profiles. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + unreachable (Sequence[str]): + Locations that could not be reached. + """ + + @property + def raw_page(self): + return self + + connection_profiles = proto.RepeatedField( + proto.MESSAGE, number=1, message=datastream_resources.ConnectionProfile, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) + + +class GetConnectionProfileRequest(proto.Message): + r"""Request message for getting a connection profile. + + Attributes: + name (str): + Required. The name of the connection profile + resource to get. + """ + + name = proto.Field(proto.STRING, number=1,) + + +class CreateConnectionProfileRequest(proto.Message): + r"""Request message for creating a connection profile. + + Attributes: + parent (str): + Required. The parent that owns the collection + of ConnectionProfiles. + connection_profile_id (str): + Required. The connection profile identifier. + connection_profile (google.cloud.datastream_v1.types.ConnectionProfile): + Required. The connection profile resource to + create. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + validate_only (bool): + Optional. Only validate the connection + profile, but don't create any resources. The + default is false. + force (bool): + Optional. Create the connection profile + without validating it. + """ + + parent = proto.Field(proto.STRING, number=1,) + connection_profile_id = proto.Field(proto.STRING, number=2,) + connection_profile = proto.Field( + proto.MESSAGE, number=3, message=datastream_resources.ConnectionProfile, + ) + request_id = proto.Field(proto.STRING, number=4,) + validate_only = proto.Field(proto.BOOL, number=5,) + force = proto.Field(proto.BOOL, number=6,) + + +class UpdateConnectionProfileRequest(proto.Message): + r"""Connection profile update message. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the ConnectionProfile resource by the update. + The fields specified in the update_mask are relative to the + resource, not the full request. A field will be overwritten + if it is in the mask. If the user does not provide a mask + then all fields will be overwritten. + connection_profile (google.cloud.datastream_v1.types.ConnectionProfile): + Required. The connection profile to update. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + validate_only (bool): + Optional. Only validate the connection + profile, but don't update any resources. The + default is false. + force (bool): + Optional. Update the connection profile + without validating it. + """ + + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) + connection_profile = proto.Field( + proto.MESSAGE, number=2, message=datastream_resources.ConnectionProfile, + ) + request_id = proto.Field(proto.STRING, number=3,) + validate_only = proto.Field(proto.BOOL, number=4,) + force = proto.Field(proto.BOOL, number=5,) + + +class DeleteConnectionProfileRequest(proto.Message): + r"""Request message for deleting a connection profile. + + Attributes: + name (str): + Required. The name of the connection profile + resource to delete. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes after the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + """ + + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) + + +class ListStreamsRequest(proto.Message): + r"""Request message for listing streams. + + Attributes: + parent (str): + Required. The parent that owns the collection + of streams. + page_size (int): + Maximum number of streams to return. + If unspecified, at most 50 streams will be + returned. The maximum value is 1000; values + above 1000 will be coerced to 1000. + page_token (str): + Page token received from a previous ``ListStreams`` call. + Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListStreams`` must match the call that provided the page + token. + filter (str): + Filter request. + order_by (str): + Order by fields for the result. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) + + +class ListStreamsResponse(proto.Message): + r"""Response message for listing streams. + + Attributes: + streams (Sequence[google.cloud.datastream_v1.types.Stream]): + List of streams + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + unreachable (Sequence[str]): + Locations that could not be reached. + """ + + @property + def raw_page(self): + return self + + streams = proto.RepeatedField( + proto.MESSAGE, number=1, message=datastream_resources.Stream, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) + + +class GetStreamRequest(proto.Message): + r"""Request message for getting a stream. + + Attributes: + name (str): + Required. The name of the stream resource to + get. + """ + + name = proto.Field(proto.STRING, number=1,) + + +class CreateStreamRequest(proto.Message): + r"""Request message for creating a stream. + + Attributes: + parent (str): + Required. The parent that owns the collection + of streams. + stream_id (str): + Required. The stream identifier. + stream (google.cloud.datastream_v1.types.Stream): + Required. The stream resource to create. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + validate_only (bool): + Optional. Only validate the stream, but don't + create any resources. The default is false. + force (bool): + Optional. Create the stream without + validating it. + """ + + parent = proto.Field(proto.STRING, number=1,) + stream_id = proto.Field(proto.STRING, number=2,) + stream = proto.Field(proto.MESSAGE, number=3, message=datastream_resources.Stream,) + request_id = proto.Field(proto.STRING, number=4,) + validate_only = proto.Field(proto.BOOL, number=5,) + force = proto.Field(proto.BOOL, number=6,) + + +class UpdateStreamRequest(proto.Message): + r"""Request message for updating a stream. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Field mask is used to specify the fields to be + overwritten in the stream resource by the update. The fields + specified in the update_mask are relative to the resource, + not the full request. A field will be overwritten if it is + in the mask. If the user does not provide a mask then all + fields will be overwritten. + stream (google.cloud.datastream_v1.types.Stream): + Required. The stream resource to update. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + validate_only (bool): + Optional. Only validate the stream with the + changes, without actually updating it. The + default is false. + force (bool): + Optional. Update the stream without + validating it. + """ + + update_mask = proto.Field( + proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + ) + stream = proto.Field(proto.MESSAGE, number=2, message=datastream_resources.Stream,) + request_id = proto.Field(proto.STRING, number=3,) + validate_only = proto.Field(proto.BOOL, number=4,) + force = proto.Field(proto.BOOL, number=5,) + + +class DeleteStreamRequest(proto.Message): + r"""Request message for deleting a stream. + + Attributes: + name (str): + Required. The name of the stream resource to + delete. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes after the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + """ + + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) + + +class GetStreamObjectRequest(proto.Message): + r"""Request for fetching a specific stream object. + + Attributes: + name (str): + Required. The name of the stream object + resource to get. + """ + + name = proto.Field(proto.STRING, number=1,) + + +class LookupStreamObjectRequest(proto.Message): + r"""Request for looking up a specific stream object by its source + object identifier. + + Attributes: + parent (str): + Required. The parent stream that owns the + collection of objects. + source_object_identifier (google.cloud.datastream_v1.types.SourceObjectIdentifier): + Required. The source object identifier which + maps to the stream object. + """ + + parent = proto.Field(proto.STRING, number=1,) + source_object_identifier = proto.Field( + proto.MESSAGE, number=2, message=datastream_resources.SourceObjectIdentifier, + ) + + +class StartBackfillJobRequest(proto.Message): + r"""Request for manually initiating a backfill job for a specific + stream object. + + Attributes: + object_ (str): + Required. The name of the stream object + resource to start a backfill job for. + """ + + object_ = proto.Field(proto.STRING, number=1,) + + +class StartBackfillJobResponse(proto.Message): + r"""Response for manually initiating a backfill job for a + specific stream object. + + Attributes: + object_ (google.cloud.datastream_v1.types.StreamObject): + The stream object resource a backfill job was + started for. + """ + + object_ = proto.Field( + proto.MESSAGE, number=1, message=datastream_resources.StreamObject, + ) + + +class StopBackfillJobRequest(proto.Message): + r"""Request for manually stopping a running backfill job for a + specific stream object. + + Attributes: + object_ (str): + Required. The name of the stream object + resource to stop the backfill job for. + """ + + object_ = proto.Field(proto.STRING, number=1,) + + +class StopBackfillJobResponse(proto.Message): + r"""Response for manually stop a backfill job for a specific + stream object. + + Attributes: + object_ (google.cloud.datastream_v1.types.StreamObject): + The stream object resource the backfill job + was stopped for. + """ + + object_ = proto.Field( + proto.MESSAGE, number=1, message=datastream_resources.StreamObject, + ) + + +class ListStreamObjectsRequest(proto.Message): + r"""Request for listing all objects for a specific stream. + + Attributes: + parent (str): + Required. The parent stream that owns the + collection of objects. + page_size (int): + Maximum number of objects to return. Default + is 50. The maximum value is 1000; values above + 1000 will be coerced to 1000. + page_token (str): + Page token received from a previous + ``ListStreamObjectsRequest`` call. Provide this to retrieve + the subsequent page. + + When paginating, all other parameters provided to + ``ListStreamObjectsRequest`` must match the call that + provided the page token. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + + +class ListStreamObjectsResponse(proto.Message): + r"""Response containing the objects for a stream. + + Attributes: + stream_objects (Sequence[google.cloud.datastream_v1.types.StreamObject]): + List of stream objects. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. + """ + + @property + def raw_page(self): + return self + + stream_objects = proto.RepeatedField( + proto.MESSAGE, number=1, message=datastream_resources.StreamObject, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + + +class OperationMetadata(proto.Message): + r"""Represents the metadata of the long-running operation. + + Attributes: + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time the operation was + created. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The time the operation finished + running. + target (str): + Output only. Server-defined resource path for + the target of the operation. + verb (str): + Output only. Name of the verb executed by the + operation. + status_message (str): + Output only. Human-readable status of the + operation, if any. + requested_cancellation (bool): + Output only. Identifies whether the user has requested + cancellation of the operation. Operations that have + successfully been cancelled have [Operation.error][] value + with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``. + api_version (str): + Output only. API version used to start the + operation. + validation_result (google.cloud.datastream_v1.types.ValidationResult): + Output only. Results of executed validations + if there are any. + """ + + create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) + end_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + target = proto.Field(proto.STRING, number=3,) + verb = proto.Field(proto.STRING, number=4,) + status_message = proto.Field(proto.STRING, number=5,) + requested_cancellation = proto.Field(proto.BOOL, number=6,) + api_version = proto.Field(proto.STRING, number=7,) + validation_result = proto.Field( + proto.MESSAGE, number=8, message=datastream_resources.ValidationResult, + ) + + +class CreatePrivateConnectionRequest(proto.Message): + r"""Request for creating a private connection. + + Attributes: + parent (str): + Required. The parent that owns the collection + of PrivateConnections. + private_connection_id (str): + Required. The private connectivity + identifier. + private_connection (google.cloud.datastream_v1.types.PrivateConnection): + Required. The Private Connectivity resource + to create. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + """ + + parent = proto.Field(proto.STRING, number=1,) + private_connection_id = proto.Field(proto.STRING, number=2,) + private_connection = proto.Field( + proto.MESSAGE, number=3, message=datastream_resources.PrivateConnection, + ) + request_id = proto.Field(proto.STRING, number=4,) + + +class ListPrivateConnectionsRequest(proto.Message): + r"""Request for listing private connections. + + Attributes: + parent (str): + Required. The parent that owns the collection + of private connectivity configurations. + page_size (int): + Maximum number of private connectivity + configurations to return. If unspecified, at + most 50 private connectivity configurations that + will be returned. The maximum value is 1000; + values above 1000 will be coerced to 1000. + page_token (str): + Page token received from a previous + ``ListPrivateConnections`` call. Provide this to retrieve + the subsequent page. + + When paginating, all other parameters provided to + ``ListPrivateConnections`` must match the call that provided + the page token. + filter (str): + Filter request. + order_by (str): + Order by fields for the result. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) + + +class ListPrivateConnectionsResponse(proto.Message): + r"""Response containing a list of private connection + configurations. + + Attributes: + private_connections (Sequence[google.cloud.datastream_v1.types.PrivateConnection]): + List of private connectivity configurations. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + unreachable (Sequence[str]): + Locations that could not be reached. + """ + + @property + def raw_page(self): + return self + + private_connections = proto.RepeatedField( + proto.MESSAGE, number=1, message=datastream_resources.PrivateConnection, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) + + +class DeletePrivateConnectionRequest(proto.Message): + r"""Request to delete a private connection. + + Attributes: + name (str): + Required. The name of the private + connectivity configuration to delete. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes after the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + force (bool): + Optional. If set to true, any child routes + that belong to this PrivateConnection will also + be deleted. + """ + + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) + force = proto.Field(proto.BOOL, number=3,) + + +class GetPrivateConnectionRequest(proto.Message): + r"""Request to get a private connection configuration. + + Attributes: + name (str): + Required. The name of the private + connectivity configuration to get. + """ + + name = proto.Field(proto.STRING, number=1,) + + +class CreateRouteRequest(proto.Message): + r"""Route creation request. + + Attributes: + parent (str): + Required. The parent that owns the collection + of Routes. + route_id (str): + Required. The Route identifier. + route (google.cloud.datastream_v1.types.Route): + Required. The Route resource to create. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes since the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + """ + + parent = proto.Field(proto.STRING, number=1,) + route_id = proto.Field(proto.STRING, number=2,) + route = proto.Field(proto.MESSAGE, number=3, message=datastream_resources.Route,) + request_id = proto.Field(proto.STRING, number=4,) + + +class ListRoutesRequest(proto.Message): + r"""Route list request. + + Attributes: + parent (str): + Required. The parent that owns the collection + of Routess. + page_size (int): + Maximum number of Routes to return. The + service may return fewer than this value. If + unspecified, at most 50 Routes will be returned. + The maximum value is 1000; values above 1000 + will be coerced to 1000. + page_token (str): + Page token received from a previous ``ListRoutes`` call. + Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + ``ListRoutes`` must match the call that provided the page + token. + filter (str): + Filter request. + order_by (str): + Order by fields for the result. + """ + + parent = proto.Field(proto.STRING, number=1,) + page_size = proto.Field(proto.INT32, number=2,) + page_token = proto.Field(proto.STRING, number=3,) + filter = proto.Field(proto.STRING, number=4,) + order_by = proto.Field(proto.STRING, number=5,) + + +class ListRoutesResponse(proto.Message): + r"""Route list response. + + Attributes: + routes (Sequence[google.cloud.datastream_v1.types.Route]): + List of Routes. + next_page_token (str): + A token, which can be sent as ``page_token`` to retrieve the + next page. If this field is omitted, there are no subsequent + pages. + unreachable (Sequence[str]): + Locations that could not be reached. + """ + + @property + def raw_page(self): + return self + + routes = proto.RepeatedField( + proto.MESSAGE, number=1, message=datastream_resources.Route, + ) + next_page_token = proto.Field(proto.STRING, number=2,) + unreachable = proto.RepeatedField(proto.STRING, number=3,) + + +class DeleteRouteRequest(proto.Message): + r"""Route deletion request. + + Attributes: + name (str): + Required. The name of the Route resource to + delete. + request_id (str): + Optional. A request ID to identify requests. + Specify a unique request ID so that if you must + retry your request, the server will know to + ignore the request if it has already been + completed. The server will guarantee that for at + least 60 minutes after the first request. + For example, consider a situation where you make + an initial request and the request times out. If + you make the request again with the same request + ID, the server can check if original operation + with the same request ID was received, and if + so, will ignore the second request. This + prevents clients from accidentally creating + duplicate commitments. + The request ID must be a valid UUID with the + exception that zero UUID is not supported + (00000000-0000-0000-0000-000000000000). + """ + + name = proto.Field(proto.STRING, number=1,) + request_id = proto.Field(proto.STRING, number=2,) + + +class GetRouteRequest(proto.Message): + r"""Route get request. + + Attributes: + name (str): + Required. The name of the Route resource to + get. + """ + + name = proto.Field(proto.STRING, number=1,) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/datastream_v1/types/datastream_resources.py b/google/cloud/datastream_v1/types/datastream_resources.py new file mode 100644 index 0000000..dd0ade4 --- /dev/null +++ b/google/cloud/datastream_v1/types/datastream_resources.py @@ -0,0 +1,1082 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 proto # type: ignore + +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.datastream.v1", + manifest={ + "OracleProfile", + "MysqlProfile", + "GcsProfile", + "StaticServiceIpConnectivity", + "ForwardSshTunnelConnectivity", + "VpcPeeringConfig", + "PrivateConnection", + "PrivateConnectivity", + "Route", + "MysqlSslConfig", + "ConnectionProfile", + "OracleColumn", + "OracleTable", + "OracleSchema", + "OracleRdbms", + "OracleSourceConfig", + "MysqlColumn", + "MysqlTable", + "MysqlDatabase", + "MysqlRdbms", + "MysqlSourceConfig", + "SourceConfig", + "AvroFileFormat", + "JsonFileFormat", + "GcsDestinationConfig", + "DestinationConfig", + "Stream", + "StreamObject", + "SourceObjectIdentifier", + "BackfillJob", + "Error", + "ValidationResult", + "Validation", + "ValidationMessage", + }, +) + + +class OracleProfile(proto.Message): + r"""Oracle database profile. + + Attributes: + hostname (str): + Required. Hostname for the Oracle connection. + port (int): + Port for the Oracle connection, default value + is 1521. + username (str): + Required. Username for the Oracle connection. + password (str): + Required. Password for the Oracle connection. + database_service (str): + Required. Database for the Oracle connection. + connection_attributes (Sequence[google.cloud.datastream_v1.types.OracleProfile.ConnectionAttributesEntry]): + Connection string attributes + """ + + hostname = proto.Field(proto.STRING, number=1,) + port = proto.Field(proto.INT32, number=2,) + username = proto.Field(proto.STRING, number=3,) + password = proto.Field(proto.STRING, number=4,) + database_service = proto.Field(proto.STRING, number=5,) + connection_attributes = proto.MapField(proto.STRING, proto.STRING, number=6,) + + +class MysqlProfile(proto.Message): + r"""MySQL database profile. + + Attributes: + hostname (str): + Required. Hostname for the MySQL connection. + port (int): + Port for the MySQL connection, default value + is 3306. + username (str): + Required. Username for the MySQL connection. + password (str): + Required. Input only. Password for the MySQL + connection. + ssl_config (google.cloud.datastream_v1.types.MysqlSslConfig): + SSL configuration for the MySQL connection. + """ + + hostname = proto.Field(proto.STRING, number=1,) + port = proto.Field(proto.INT32, number=2,) + username = proto.Field(proto.STRING, number=3,) + password = proto.Field(proto.STRING, number=4,) + ssl_config = proto.Field(proto.MESSAGE, number=5, message="MysqlSslConfig",) + + +class GcsProfile(proto.Message): + r"""Cloud Storage bucket profile. + + Attributes: + bucket (str): + Required. The Cloud Storage bucket name. + root_path (str): + The root path inside the Cloud Storage + bucket. + """ + + bucket = proto.Field(proto.STRING, number=1,) + root_path = proto.Field(proto.STRING, number=2,) + + +class StaticServiceIpConnectivity(proto.Message): + r"""Static IP address connectivity. + """ + + +class ForwardSshTunnelConnectivity(proto.Message): + r"""Forward SSH Tunnel connectivity. + + 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: + hostname (str): + Required. Hostname for the SSH tunnel. + username (str): + Required. Username for the SSH tunnel. + port (int): + Port for the SSH tunnel, default value is 22. + password (str): + Input only. SSH password. + + This field is a member of `oneof`_ ``authentication_method``. + private_key (str): + Input only. SSH private key. + + This field is a member of `oneof`_ ``authentication_method``. + """ + + hostname = proto.Field(proto.STRING, number=1,) + username = proto.Field(proto.STRING, number=2,) + port = proto.Field(proto.INT32, number=3,) + password = proto.Field(proto.STRING, number=100, oneof="authentication_method",) + private_key = proto.Field(proto.STRING, number=101, oneof="authentication_method",) + + +class VpcPeeringConfig(proto.Message): + r"""The VPC Peering configuration is used to create VPC peering + between Datastream and the consumer's VPC. + + Attributes: + vpc (str): + Required. Fully qualified name of the VPC that Datastream + will peer to. Format: + ``projects/{project}/global/{networks}/{name}`` + subnet (str): + Required. A free subnet for peering. (CIDR of + /29) + """ + + vpc = proto.Field(proto.STRING, number=1,) + subnet = proto.Field(proto.STRING, number=2,) + + +class PrivateConnection(proto.Message): + r"""The PrivateConnection resource is used to establish private + connectivity between Datastream and a customer's network. + + Attributes: + name (str): + Output only. The resource's name. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The create time of the resource. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The update time of the resource. + labels (Sequence[google.cloud.datastream_v1.types.PrivateConnection.LabelsEntry]): + Labels. + display_name (str): + Required. Display name. + state (google.cloud.datastream_v1.types.PrivateConnection.State): + Output only. The state of the Private + Connection. + error (google.cloud.datastream_v1.types.Error): + Output only. In case of error, the details of + the error in a user-friendly format. + vpc_peering_config (google.cloud.datastream_v1.types.VpcPeeringConfig): + VPC Peering Config. + """ + + class State(proto.Enum): + r"""Private Connection state.""" + STATE_UNSPECIFIED = 0 + CREATING = 1 + CREATED = 2 + FAILED = 3 + DELETING = 4 + FAILED_TO_DELETE = 5 + + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + display_name = proto.Field(proto.STRING, number=5,) + state = proto.Field(proto.ENUM, number=6, enum=State,) + error = proto.Field(proto.MESSAGE, number=7, message="Error",) + vpc_peering_config = proto.Field( + proto.MESSAGE, number=100, message="VpcPeeringConfig", + ) + + +class PrivateConnectivity(proto.Message): + r"""Private Connectivity + + Attributes: + private_connection (str): + Required. A reference to a private connection resource. + Format: + ``projects/{project}/locations/{location}/privateConnections/{name}`` + """ + + private_connection = proto.Field(proto.STRING, number=1,) + + +class Route(proto.Message): + r"""The route resource is the child of the private connection + resource, used for defining a route for a private connection. + + Attributes: + name (str): + Output only. The resource's name. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The create time of the resource. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The update time of the resource. + labels (Sequence[google.cloud.datastream_v1.types.Route.LabelsEntry]): + Labels. + display_name (str): + Required. Display name. + destination_address (str): + Required. Destination address for connection + destination_port (int): + Destination port for connection + """ + + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + display_name = proto.Field(proto.STRING, number=5,) + destination_address = proto.Field(proto.STRING, number=6,) + destination_port = proto.Field(proto.INT32, number=7,) + + +class MysqlSslConfig(proto.Message): + r"""MySQL SSL configuration information. + + Attributes: + client_key (str): + Input only. PEM-encoded private key associated with the + Client Certificate. If this field is used then the + 'client_certificate' and the 'ca_certificate' fields are + mandatory. + client_key_set (bool): + Output only. Indicates whether the client_key field is set. + client_certificate (str): + Input only. PEM-encoded certificate that will be used by the + replica to authenticate against the source database server. + If this field is used then the 'client_key' and the + 'ca_certificate' fields are mandatory. + client_certificate_set (bool): + Output only. Indicates whether the client_certificate field + is set. + ca_certificate (str): + Input only. PEM-encoded certificate of the CA + that signed the source database server's + certificate. + ca_certificate_set (bool): + Output only. Indicates whether the ca_certificate field is + set. + """ + + client_key = proto.Field(proto.STRING, number=1,) + client_key_set = proto.Field(proto.BOOL, number=2,) + client_certificate = proto.Field(proto.STRING, number=3,) + client_certificate_set = proto.Field(proto.BOOL, number=4,) + ca_certificate = proto.Field(proto.STRING, number=5,) + ca_certificate_set = proto.Field(proto.BOOL, number=6,) + + +class ConnectionProfile(proto.Message): + r"""A set of reusable connection configurations to be used as a + source or destination for a stream. + + 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: + name (str): + Output only. The resource's name. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The create time of the resource. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The update time of the resource. + labels (Sequence[google.cloud.datastream_v1.types.ConnectionProfile.LabelsEntry]): + Labels. + display_name (str): + Required. Display name. + oracle_profile (google.cloud.datastream_v1.types.OracleProfile): + Oracle ConnectionProfile configuration. + + This field is a member of `oneof`_ ``profile``. + gcs_profile (google.cloud.datastream_v1.types.GcsProfile): + Cloud Storage ConnectionProfile + configuration. + + This field is a member of `oneof`_ ``profile``. + mysql_profile (google.cloud.datastream_v1.types.MysqlProfile): + MySQL ConnectionProfile configuration. + + This field is a member of `oneof`_ ``profile``. + static_service_ip_connectivity (google.cloud.datastream_v1.types.StaticServiceIpConnectivity): + Static Service IP connectivity. + + This field is a member of `oneof`_ ``connectivity``. + forward_ssh_connectivity (google.cloud.datastream_v1.types.ForwardSshTunnelConnectivity): + Forward SSH tunnel connectivity. + + This field is a member of `oneof`_ ``connectivity``. + private_connectivity (google.cloud.datastream_v1.types.PrivateConnectivity): + Private connectivity. + + This field is a member of `oneof`_ ``connectivity``. + """ + + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + display_name = proto.Field(proto.STRING, number=5,) + oracle_profile = proto.Field( + proto.MESSAGE, number=100, oneof="profile", message="OracleProfile", + ) + gcs_profile = proto.Field( + proto.MESSAGE, number=101, oneof="profile", message="GcsProfile", + ) + mysql_profile = proto.Field( + proto.MESSAGE, number=102, oneof="profile", message="MysqlProfile", + ) + static_service_ip_connectivity = proto.Field( + proto.MESSAGE, + number=200, + oneof="connectivity", + message="StaticServiceIpConnectivity", + ) + forward_ssh_connectivity = proto.Field( + proto.MESSAGE, + number=201, + oneof="connectivity", + message="ForwardSshTunnelConnectivity", + ) + private_connectivity = proto.Field( + proto.MESSAGE, number=202, oneof="connectivity", message="PrivateConnectivity", + ) + + +class OracleColumn(proto.Message): + r"""Oracle Column. + + Attributes: + column (str): + Column name. + data_type (str): + The Oracle data type. + length (int): + Column length. + precision (int): + Column precision. + scale (int): + Column scale. + encoding (str): + Column encoding. + primary_key (bool): + Whether or not the column represents a + primary key. + nullable (bool): + Whether or not the column can accept a null + value. + ordinal_position (int): + The ordinal position of the column in the + table. + """ + + column = proto.Field(proto.STRING, number=1,) + data_type = proto.Field(proto.STRING, number=2,) + length = proto.Field(proto.INT32, number=3,) + precision = proto.Field(proto.INT32, number=4,) + scale = proto.Field(proto.INT32, number=5,) + encoding = proto.Field(proto.STRING, number=6,) + primary_key = proto.Field(proto.BOOL, number=7,) + nullable = proto.Field(proto.BOOL, number=8,) + ordinal_position = proto.Field(proto.INT32, number=9,) + + +class OracleTable(proto.Message): + r"""Oracle table. + + Attributes: + table (str): + Table name. + oracle_columns (Sequence[google.cloud.datastream_v1.types.OracleColumn]): + Oracle columns in the schema. + When unspecified as part of inclue/exclude + lists, includes/excludes everything. + """ + + table = proto.Field(proto.STRING, number=1,) + oracle_columns = proto.RepeatedField( + proto.MESSAGE, number=2, message="OracleColumn", + ) + + +class OracleSchema(proto.Message): + r"""Oracle schema. + + Attributes: + schema (str): + Schema name. + oracle_tables (Sequence[google.cloud.datastream_v1.types.OracleTable]): + Tables in the schema. + """ + + schema = proto.Field(proto.STRING, number=1,) + oracle_tables = proto.RepeatedField(proto.MESSAGE, number=2, message="OracleTable",) + + +class OracleRdbms(proto.Message): + r"""Oracle database structure. + + Attributes: + oracle_schemas (Sequence[google.cloud.datastream_v1.types.OracleSchema]): + Oracle schemas/databases in the database + server. + """ + + oracle_schemas = proto.RepeatedField( + proto.MESSAGE, number=1, message="OracleSchema", + ) + + +class OracleSourceConfig(proto.Message): + r"""Oracle data source configuration + + Attributes: + include_objects (google.cloud.datastream_v1.types.OracleRdbms): + Oracle objects to include in the stream. + exclude_objects (google.cloud.datastream_v1.types.OracleRdbms): + Oracle objects to exclude from the stream. + """ + + include_objects = proto.Field(proto.MESSAGE, number=1, message="OracleRdbms",) + exclude_objects = proto.Field(proto.MESSAGE, number=2, message="OracleRdbms",) + + +class MysqlColumn(proto.Message): + r"""MySQL Column. + + Attributes: + column (str): + Column name. + data_type (str): + The MySQL data type. Full data types list can + be found here: + https://dev.mysql.com/doc/refman/8.0/en/data-types.html + length (int): + Column length. + collation (str): + Column collation. + primary_key (bool): + Whether or not the column represents a + primary key. + nullable (bool): + Whether or not the column can accept a null + value. + ordinal_position (int): + The ordinal position of the column in the + table. + """ + + column = proto.Field(proto.STRING, number=1,) + data_type = proto.Field(proto.STRING, number=2,) + length = proto.Field(proto.INT32, number=3,) + collation = proto.Field(proto.STRING, number=4,) + primary_key = proto.Field(proto.BOOL, number=5,) + nullable = proto.Field(proto.BOOL, number=6,) + ordinal_position = proto.Field(proto.INT32, number=7,) + + +class MysqlTable(proto.Message): + r"""MySQL table. + + Attributes: + table (str): + Table name. + mysql_columns (Sequence[google.cloud.datastream_v1.types.MysqlColumn]): + MySQL columns in the database. + When unspecified as part of include/exclude + lists, includes/excludes everything. + """ + + table = proto.Field(proto.STRING, number=1,) + mysql_columns = proto.RepeatedField(proto.MESSAGE, number=2, message="MysqlColumn",) + + +class MysqlDatabase(proto.Message): + r"""MySQL database. + + Attributes: + database (str): + Database name. + mysql_tables (Sequence[google.cloud.datastream_v1.types.MysqlTable]): + Tables in the database. + """ + + database = proto.Field(proto.STRING, number=1,) + mysql_tables = proto.RepeatedField(proto.MESSAGE, number=2, message="MysqlTable",) + + +class MysqlRdbms(proto.Message): + r"""MySQL database structure + + Attributes: + mysql_databases (Sequence[google.cloud.datastream_v1.types.MysqlDatabase]): + Mysql databases on the server + """ + + mysql_databases = proto.RepeatedField( + proto.MESSAGE, number=1, message="MysqlDatabase", + ) + + +class MysqlSourceConfig(proto.Message): + r"""MySQL source configuration + + Attributes: + include_objects (google.cloud.datastream_v1.types.MysqlRdbms): + MySQL objects to retrieve from the source. + exclude_objects (google.cloud.datastream_v1.types.MysqlRdbms): + MySQL objects to exclude from the stream. + """ + + include_objects = proto.Field(proto.MESSAGE, number=1, message="MysqlRdbms",) + exclude_objects = proto.Field(proto.MESSAGE, number=2, message="MysqlRdbms",) + + +class SourceConfig(proto.Message): + r"""The configuration of the stream source. + + 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: + source_connection_profile (str): + Required. Source connection profile resoource. Format: + ``projects/{project}/locations/{location}/connectionProfiles/{name}`` + oracle_source_config (google.cloud.datastream_v1.types.OracleSourceConfig): + Oracle data source configuration + + This field is a member of `oneof`_ ``source_stream_config``. + mysql_source_config (google.cloud.datastream_v1.types.MysqlSourceConfig): + MySQL data source configuration + + This field is a member of `oneof`_ ``source_stream_config``. + """ + + source_connection_profile = proto.Field(proto.STRING, number=1,) + oracle_source_config = proto.Field( + proto.MESSAGE, + number=100, + oneof="source_stream_config", + message="OracleSourceConfig", + ) + mysql_source_config = proto.Field( + proto.MESSAGE, + number=101, + oneof="source_stream_config", + message="MysqlSourceConfig", + ) + + +class AvroFileFormat(proto.Message): + r"""AVRO file format configuration. + """ + + +class JsonFileFormat(proto.Message): + r"""JSON file format configuration. + + Attributes: + schema_file_format (google.cloud.datastream_v1.types.JsonFileFormat.SchemaFileFormat): + The schema file format along JSON data files. + compression (google.cloud.datastream_v1.types.JsonFileFormat.JsonCompression): + Compression of the loaded JSON file. + """ + + class SchemaFileFormat(proto.Enum): + r"""Schema file format.""" + SCHEMA_FILE_FORMAT_UNSPECIFIED = 0 + NO_SCHEMA_FILE = 1 + AVRO_SCHEMA_FILE = 2 + + class JsonCompression(proto.Enum): + r"""Json file compression.""" + JSON_COMPRESSION_UNSPECIFIED = 0 + NO_COMPRESSION = 1 + GZIP = 2 + + schema_file_format = proto.Field(proto.ENUM, number=1, enum=SchemaFileFormat,) + compression = proto.Field(proto.ENUM, number=2, enum=JsonCompression,) + + +class GcsDestinationConfig(proto.Message): + r"""Google Cloud Storage destination configuration + + 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: + path (str): + Path inside the Cloud Storage bucket to write + data to. + file_rotation_mb (int): + The maximum file size to be saved in the + bucket. + file_rotation_interval (google.protobuf.duration_pb2.Duration): + The maximum duration for which new events are + added before a file is closed and a new file is + created. + avro_file_format (google.cloud.datastream_v1.types.AvroFileFormat): + AVRO file format configuration. + + This field is a member of `oneof`_ ``file_format``. + json_file_format (google.cloud.datastream_v1.types.JsonFileFormat): + JSON file format configuration. + + This field is a member of `oneof`_ ``file_format``. + """ + + path = proto.Field(proto.STRING, number=1,) + file_rotation_mb = proto.Field(proto.INT32, number=2,) + file_rotation_interval = proto.Field( + proto.MESSAGE, number=3, message=duration_pb2.Duration, + ) + avro_file_format = proto.Field( + proto.MESSAGE, number=100, oneof="file_format", message="AvroFileFormat", + ) + json_file_format = proto.Field( + proto.MESSAGE, number=101, oneof="file_format", message="JsonFileFormat", + ) + + +class DestinationConfig(proto.Message): + r"""The configuration of the stream destination. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + destination_connection_profile (str): + Required. Destination connection profile resource. Format: + ``projects/{project}/locations/{location}/connectionProfiles/{name}`` + gcs_destination_config (google.cloud.datastream_v1.types.GcsDestinationConfig): + A configuration for how data should be loaded + to Cloud Storage. + + This field is a member of `oneof`_ ``destination_stream_config``. + """ + + destination_connection_profile = proto.Field(proto.STRING, number=1,) + gcs_destination_config = proto.Field( + proto.MESSAGE, + number=100, + oneof="destination_stream_config", + message="GcsDestinationConfig", + ) + + +class Stream(proto.Message): + r"""A resource representing streaming data from a source to a + destination. + + 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: + name (str): + Output only. The stream's name. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The creation time of the stream. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The last update time of the + stream. + labels (Sequence[google.cloud.datastream_v1.types.Stream.LabelsEntry]): + Labels. + display_name (str): + Required. Display name. + source_config (google.cloud.datastream_v1.types.SourceConfig): + Required. Source connection profile + configuration. + destination_config (google.cloud.datastream_v1.types.DestinationConfig): + Required. Destination connection profile + configuration. + state (google.cloud.datastream_v1.types.Stream.State): + The state of the stream. + backfill_all (google.cloud.datastream_v1.types.Stream.BackfillAllStrategy): + Automatically backfill objects included in + the stream source configuration. Specific + objects can be excluded. + + This field is a member of `oneof`_ ``backfill_strategy``. + backfill_none (google.cloud.datastream_v1.types.Stream.BackfillNoneStrategy): + Do not automatically backfill any objects. + + This field is a member of `oneof`_ ``backfill_strategy``. + errors (Sequence[google.cloud.datastream_v1.types.Error]): + Output only. Errors on the Stream. + customer_managed_encryption_key (str): + Immutable. A reference to a KMS encryption + key. If provided, it will be used to encrypt the + data. If left blank, data will be encrypted + using an internal Stream-specific encryption key + provisioned through KMS. + + This field is a member of `oneof`_ ``_customer_managed_encryption_key``. + """ + + class State(proto.Enum): + r"""Stream state.""" + STATE_UNSPECIFIED = 0 + NOT_STARTED = 1 + RUNNING = 2 + PAUSED = 3 + MAINTENANCE = 4 + FAILED = 5 + FAILED_PERMANENTLY = 6 + STARTING = 7 + DRAINING = 8 + + class BackfillAllStrategy(proto.Message): + r"""Backfill strategy to automatically backfill the Stream's + objects. Specific objects can be excluded. + + 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: + oracle_excluded_objects (google.cloud.datastream_v1.types.OracleRdbms): + Oracle data source objects to avoid + backfilling. + + This field is a member of `oneof`_ ``excluded_objects``. + mysql_excluded_objects (google.cloud.datastream_v1.types.MysqlRdbms): + MySQL data source objects to avoid + backfilling. + + This field is a member of `oneof`_ ``excluded_objects``. + """ + + oracle_excluded_objects = proto.Field( + proto.MESSAGE, number=1, oneof="excluded_objects", message="OracleRdbms", + ) + mysql_excluded_objects = proto.Field( + proto.MESSAGE, number=2, oneof="excluded_objects", message="MysqlRdbms", + ) + + class BackfillNoneStrategy(proto.Message): + r"""Backfill strategy to disable automatic backfill for the + Stream's objects. + + """ + + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + labels = proto.MapField(proto.STRING, proto.STRING, number=4,) + display_name = proto.Field(proto.STRING, number=5,) + source_config = proto.Field(proto.MESSAGE, number=6, message="SourceConfig",) + destination_config = proto.Field( + proto.MESSAGE, number=7, message="DestinationConfig", + ) + state = proto.Field(proto.ENUM, number=8, enum=State,) + backfill_all = proto.Field( + proto.MESSAGE, + number=101, + oneof="backfill_strategy", + message=BackfillAllStrategy, + ) + backfill_none = proto.Field( + proto.MESSAGE, + number=102, + oneof="backfill_strategy", + message=BackfillNoneStrategy, + ) + errors = proto.RepeatedField(proto.MESSAGE, number=9, message="Error",) + customer_managed_encryption_key = proto.Field( + proto.STRING, number=10, optional=True, + ) + + +class StreamObject(proto.Message): + r"""A specific stream object (e.g a specific DB table). + + Attributes: + name (str): + Output only. The object resource's name. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The creation time of the object. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The last update time of the + object. + display_name (str): + Required. Display name. + errors (Sequence[google.cloud.datastream_v1.types.Error]): + Output only. Active errors on the object. + backfill_job (google.cloud.datastream_v1.types.BackfillJob): + The latest backfill job that was initiated + for the stream object. + source_object (google.cloud.datastream_v1.types.SourceObjectIdentifier): + The object identifier in the data source. + """ + + name = proto.Field(proto.STRING, number=1,) + create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) + update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) + display_name = proto.Field(proto.STRING, number=5,) + errors = proto.RepeatedField(proto.MESSAGE, number=6, message="Error",) + backfill_job = proto.Field(proto.MESSAGE, number=7, message="BackfillJob",) + source_object = proto.Field( + proto.MESSAGE, number=8, message="SourceObjectIdentifier", + ) + + +class SourceObjectIdentifier(proto.Message): + r"""Represents an identifier of an object in the data source. + + 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: + oracle_identifier (google.cloud.datastream_v1.types.SourceObjectIdentifier.OracleObjectIdentifier): + Oracle data source object identifier. + + This field is a member of `oneof`_ ``source_identifier``. + mysql_identifier (google.cloud.datastream_v1.types.SourceObjectIdentifier.MysqlObjectIdentifier): + Mysql data source object identifier. + + This field is a member of `oneof`_ ``source_identifier``. + """ + + class OracleObjectIdentifier(proto.Message): + r"""Oracle data source object identifier. + + Attributes: + schema (str): + Required. The schema name. + table (str): + Required. The table name. + """ + + schema = proto.Field(proto.STRING, number=1,) + table = proto.Field(proto.STRING, number=2,) + + class MysqlObjectIdentifier(proto.Message): + r"""Mysql data source object identifier. + + Attributes: + database (str): + Required. The database name. + table (str): + Required. The table name. + """ + + database = proto.Field(proto.STRING, number=1,) + table = proto.Field(proto.STRING, number=2,) + + oracle_identifier = proto.Field( + proto.MESSAGE, + number=1, + oneof="source_identifier", + message=OracleObjectIdentifier, + ) + mysql_identifier = proto.Field( + proto.MESSAGE, + number=2, + oneof="source_identifier", + message=MysqlObjectIdentifier, + ) + + +class BackfillJob(proto.Message): + r"""Represents a backfill job on a specific stream object. + + Attributes: + state (google.cloud.datastream_v1.types.BackfillJob.State): + Backfill job state. + trigger (google.cloud.datastream_v1.types.BackfillJob.Trigger): + Backfill job's triggering reason. + last_start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Backfill job's start time. + last_end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Backfill job's end time. + errors (Sequence[google.cloud.datastream_v1.types.Error]): + Output only. Errors which caused the backfill + job to fail. + """ + + class State(proto.Enum): + r"""State of the stream object's backfill job.""" + STATE_UNSPECIFIED = 0 + NOT_STARTED = 1 + PENDING = 2 + ACTIVE = 3 + STOPPED = 4 + FAILED = 5 + COMPLETED = 6 + UNSUPPORTED = 7 + + class Trigger(proto.Enum): + r"""Triggering reason for a backfill job.""" + TRIGGER_UNSPECIFIED = 0 + AUTOMATIC = 1 + MANUAL = 2 + + state = proto.Field(proto.ENUM, number=1, enum=State,) + trigger = proto.Field(proto.ENUM, number=2, enum=Trigger,) + last_start_time = proto.Field( + proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp, + ) + last_end_time = proto.Field( + proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp, + ) + errors = proto.RepeatedField(proto.MESSAGE, number=5, message="Error",) + + +class Error(proto.Message): + r"""Represent a user-facing Error. + + Attributes: + reason (str): + A title that explains the reason for the + error. + error_uuid (str): + A unique identifier for this specific error, + allowing it to be traced throughout the system + in logs and API responses. + message (str): + A message containing more information about + the error that occurred. + error_time (google.protobuf.timestamp_pb2.Timestamp): + The time when the error occurred. + details (Sequence[google.cloud.datastream_v1.types.Error.DetailsEntry]): + Additional information about the error. + """ + + reason = proto.Field(proto.STRING, number=1,) + error_uuid = proto.Field(proto.STRING, number=2,) + message = proto.Field(proto.STRING, number=3,) + error_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + details = proto.MapField(proto.STRING, proto.STRING, number=5,) + + +class ValidationResult(proto.Message): + r"""Contains the current validation results. + + Attributes: + validations (Sequence[google.cloud.datastream_v1.types.Validation]): + A list of validations (includes both executed + as well as not executed validations). + """ + + validations = proto.RepeatedField(proto.MESSAGE, number=1, message="Validation",) + + +class Validation(proto.Message): + r"""A validation to perform on a stream. + + Attributes: + description (str): + A short description of the validation. + state (google.cloud.datastream_v1.types.Validation.State): + Validation execution status. + message (Sequence[google.cloud.datastream_v1.types.ValidationMessage]): + Messages reflecting the validation results. + code (str): + A custom code identifying this validation. + """ + + class State(proto.Enum): + r"""Validation execution state.""" + STATE_UNSPECIFIED = 0 + NOT_EXECUTED = 1 + FAILED = 2 + PASSED = 3 + + description = proto.Field(proto.STRING, number=1,) + state = proto.Field(proto.ENUM, number=2, enum=State,) + message = proto.RepeatedField(proto.MESSAGE, number=3, message="ValidationMessage",) + code = proto.Field(proto.STRING, number=4,) + + +class ValidationMessage(proto.Message): + r"""Represent user-facing validation result message. + + Attributes: + message (str): + The result of the validation. + level (google.cloud.datastream_v1.types.ValidationMessage.Level): + Message severity level (warning or error). + metadata (Sequence[google.cloud.datastream_v1.types.ValidationMessage.MetadataEntry]): + Additional metadata related to the result. + code (str): + A custom code identifying this specific + message. + """ + + class Level(proto.Enum): + r"""Validation message level.""" + LEVEL_UNSPECIFIED = 0 + WARNING = 1 + ERROR = 2 + + message = proto.Field(proto.STRING, number=1,) + level = proto.Field(proto.ENUM, number=2, enum=Level,) + metadata = proto.MapField(proto.STRING, proto.STRING, number=3,) + code = proto.Field(proto.STRING, number=4,) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py index 1f19b42..7d5c834 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/async_client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/async_client.py @@ -248,7 +248,7 @@ async def list_connection_profiles( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -323,7 +323,7 @@ async def get_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -412,7 +412,7 @@ async def create_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, connection_profile, connection_profile_id]) if request is not None and has_flattened_params: @@ -510,7 +510,7 @@ async def update_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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([connection_profile, update_mask]) if request is not None and has_flattened_params: @@ -605,7 +605,7 @@ async def delete_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -736,7 +736,7 @@ async def list_streams( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -810,7 +810,7 @@ async def get_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -896,7 +896,7 @@ async def create_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, stream, stream_id]) if request is not None and has_flattened_params: @@ -993,7 +993,7 @@ async def update_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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([stream, update_mask]) if request is not None and has_flattened_params: @@ -1088,7 +1088,7 @@ async def delete_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1234,7 +1234,7 @@ async def fetch_static_ips( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1329,7 +1329,7 @@ async def create_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, private_connection, private_connection_id]) if request is not None and has_flattened_params: @@ -1414,7 +1414,7 @@ async def get_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1487,7 +1487,7 @@ async def list_private_connections( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1577,7 +1577,7 @@ async def delete_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1673,7 +1673,7 @@ async def create_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, route, route_id]) if request is not None and has_flattened_params: @@ -1757,7 +1757,7 @@ async def get_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1830,7 +1830,7 @@ async def list_routes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1919,7 +1919,7 @@ async def delete_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: diff --git a/google/cloud/datastream_v1alpha1/services/datastream/client.py b/google/cloud/datastream_v1alpha1/services/datastream/client.py index 9ccdfe1..53794fa 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/client.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/client.py @@ -496,7 +496,7 @@ def list_connection_profiles( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -571,7 +571,7 @@ def get_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -660,7 +660,7 @@ def create_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, connection_profile, connection_profile_id]) if request is not None and has_flattened_params: @@ -760,7 +760,7 @@ def update_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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([connection_profile, update_mask]) if request is not None and has_flattened_params: @@ -857,7 +857,7 @@ def delete_connection_profile( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -993,7 +993,7 @@ def list_streams( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1067,7 +1067,7 @@ def get_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1153,7 +1153,7 @@ def create_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, stream, stream_id]) if request is not None and has_flattened_params: @@ -1250,7 +1250,7 @@ def update_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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([stream, update_mask]) if request is not None and has_flattened_params: @@ -1345,7 +1345,7 @@ def delete_stream( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1492,7 +1492,7 @@ def fetch_static_ips( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1587,7 +1587,7 @@ def create_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, private_connection, private_connection_id]) if request is not None and has_flattened_params: @@ -1674,7 +1674,7 @@ def get_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1747,7 +1747,7 @@ def list_private_connections( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1837,7 +1837,7 @@ def delete_private_connection( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -1935,7 +1935,7 @@ def create_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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, route, route_id]) if request is not None and has_flattened_params: @@ -2019,7 +2019,7 @@ def get_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -2092,7 +2092,7 @@ def list_routes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: @@ -2181,7 +2181,7 @@ def delete_route( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # 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: diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py index dd346d4..392cb31 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc.py @@ -162,8 +162,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # 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, @@ -236,7 +239,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # 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) diff --git a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py index e4cafda..d50d487 100644 --- a/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py +++ b/google/cloud/datastream_v1alpha1/services/datastream/transports/grpc_asyncio.py @@ -207,8 +207,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # 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, @@ -238,7 +241,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # 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 diff --git a/google/cloud/datastream_v1alpha1/types/datastream_resources.py b/google/cloud/datastream_v1alpha1/types/datastream_resources.py index 4f1da74..8a41a4b 100644 --- a/google/cloud/datastream_v1alpha1/types/datastream_resources.py +++ b/google/cloud/datastream_v1alpha1/types/datastream_resources.py @@ -521,8 +521,7 @@ class MysqlColumn(proto.Message): data_type (str): The MySQL data type. Full data types list can be found here: - https://dev.mysql.com/doc/refman/8.0/en/data- - types.html + https://dev.mysql.com/doc/refman/8.0/en/data-types.html length (int): Column length. collation (str): diff --git a/scripts/fixup_datastream_v1_keywords.py b/scripts/fixup_datastream_v1_keywords.py new file mode 100644 index 0000000..00b466f --- /dev/null +++ b/scripts/fixup_datastream_v1_keywords.py @@ -0,0 +1,200 @@ +#! /usr/bin/env python3 +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 datastreamCallTransformer(cst.CSTTransformer): + CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') + METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { + 'create_connection_profile': ('parent', 'connection_profile_id', 'connection_profile', 'request_id', 'validate_only', 'force', ), + 'create_private_connection': ('parent', 'private_connection_id', 'private_connection', 'request_id', ), + 'create_route': ('parent', 'route_id', 'route', 'request_id', ), + 'create_stream': ('parent', 'stream_id', 'stream', 'request_id', 'validate_only', 'force', ), + 'delete_connection_profile': ('name', 'request_id', ), + 'delete_private_connection': ('name', 'request_id', 'force', ), + 'delete_route': ('name', 'request_id', ), + 'delete_stream': ('name', 'request_id', ), + 'discover_connection_profile': ('parent', 'connection_profile', 'connection_profile_name', 'full_hierarchy', 'hierarchy_depth', 'oracle_rdbms', 'mysql_rdbms', ), + 'fetch_static_ips': ('name', 'page_size', 'page_token', ), + 'get_connection_profile': ('name', ), + 'get_private_connection': ('name', ), + 'get_route': ('name', ), + 'get_stream': ('name', ), + 'get_stream_object': ('name', ), + 'list_connection_profiles': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'list_private_connections': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'list_routes': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'list_stream_objects': ('parent', 'page_size', 'page_token', ), + 'list_streams': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ), + 'lookup_stream_object': ('parent', 'source_object_identifier', ), + 'start_backfill_job': ('object_', ), + 'stop_backfill_job': ('object_', ), + 'update_connection_profile': ('connection_profile', 'update_mask', 'request_id', 'validate_only', 'force', ), + 'update_stream': ('stream', 'update_mask', 'request_id', 'validate_only', 'force', ), + } + + 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=datastreamCallTransformer(), +): + """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 datastream 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/tests/unit/gapic/datastream_v1/__init__.py b/tests/unit/gapic/datastream_v1/__init__.py new file mode 100644 index 0000000..4de6597 --- /dev/null +++ b/tests/unit/gapic/datastream_v1/__init__.py @@ -0,0 +1,15 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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/tests/unit/gapic/datastream_v1/test_datastream.py b/tests/unit/gapic/datastream_v1/test_datastream.py new file mode 100644 index 0000000..95c5efa --- /dev/null +++ b/tests/unit/gapic/datastream_v1/test_datastream.py @@ -0,0 +1,7570 @@ +# -*- 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT 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 mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +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.datastream_v1.services.datastream import DatastreamAsyncClient +from google.cloud.datastream_v1.services.datastream import DatastreamClient +from google.cloud.datastream_v1.services.datastream import pagers +from google.cloud.datastream_v1.services.datastream import transports +from google.cloud.datastream_v1.types import datastream +from google.cloud.datastream_v1.types import datastream_resources +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_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 DatastreamClient._get_default_mtls_endpoint(None) is None + assert ( + DatastreamClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + ) + assert ( + DatastreamClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + DatastreamClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + DatastreamClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert DatastreamClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize("client_class", [DatastreamClient, DatastreamAsyncClient,]) +def test_datastream_client_from_service_account_info(client_class): + 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) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "datastream.googleapis.com:443" + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DatastreamGrpcTransport, "grpc"), + (transports.DatastreamGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_datastream_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", [DatastreamClient, DatastreamAsyncClient,]) +def test_datastream_client_from_service_account_file(client_class): + 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") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json("dummy/file/path.json") + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == "datastream.googleapis.com:443" + + +def test_datastream_client_get_transport_class(): + transport = DatastreamClient.get_transport_class() + available_transports = [ + transports.DatastreamGrpcTransport, + ] + assert transport in available_transports + + transport = DatastreamClient.get_transport_class("grpc") + assert transport == transports.DatastreamGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc"), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + DatastreamClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatastreamClient) +) +@mock.patch.object( + DatastreamAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatastreamAsyncClient), +) +def test_datastream_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(DatastreamClient, "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(DatastreamClient, "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, + ) + + # 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, + ) + + # 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, + ) + + # 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, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", "true"), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", "false"), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + DatastreamClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatastreamClient) +) +@mock.patch.object( + DatastreamAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatastreamAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_datastream_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, + ) + + # 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, + ) + + # 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, + ) + + +@pytest.mark.parametrize("client_class", [DatastreamClient, DatastreamAsyncClient]) +@mock.patch.object( + DatastreamClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DatastreamClient) +) +@mock.patch.object( + DatastreamAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatastreamAsyncClient), +) +def test_datastream_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", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc"), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_datastream_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, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", grpc_helpers), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_datastream_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, + ) + + +def test_datastream_client_client_options_from_dict(): + with mock.patch( + "google.cloud.datastream_v1.services.datastream.transports.DatastreamGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = DatastreamClient(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, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", grpc_helpers), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_datastream_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, + ) + + # 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( + "datastream.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="datastream.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.ListConnectionProfilesRequest, dict,] +) +def test_list_connection_profiles(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_connection_profiles), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListConnectionProfilesResponse( + next_page_token="next_page_token_value", unreachable=["unreachable_value"], + ) + response = client.list_connection_profiles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListConnectionProfilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListConnectionProfilesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_connection_profiles_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 = DatastreamClient( + 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_connection_profiles), "__call__" + ) as call: + client.list_connection_profiles() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListConnectionProfilesRequest() + + +@pytest.mark.asyncio +async def test_list_connection_profiles_async( + transport: str = "grpc_asyncio", + request_type=datastream.ListConnectionProfilesRequest, +): + client = DatastreamAsyncClient( + 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_connection_profiles), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListConnectionProfilesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + response = await client.list_connection_profiles(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListConnectionProfilesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListConnectionProfilesAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.asyncio +async def test_list_connection_profiles_async_from_dict(): + await test_list_connection_profiles_async(request_type=dict) + + +def test_list_connection_profiles_field_headers(): + client = DatastreamClient(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 = datastream.ListConnectionProfilesRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), "__call__" + ) as call: + call.return_value = datastream.ListConnectionProfilesResponse() + client.list_connection_profiles(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_connection_profiles_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.ListConnectionProfilesRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListConnectionProfilesResponse() + ) + await client.list_connection_profiles(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_connection_profiles_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListConnectionProfilesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_connection_profiles(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_connection_profiles_flattened_error(): + client = DatastreamClient(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_connection_profiles( + datastream.ListConnectionProfilesRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_connection_profiles_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListConnectionProfilesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListConnectionProfilesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_connection_profiles(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_connection_profiles_flattened_error_async(): + client = DatastreamAsyncClient(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_connection_profiles( + datastream.ListConnectionProfilesRequest(), parent="parent_value", + ) + + +def test_list_connection_profiles_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_connection_profiles), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + next_page_token="abc", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[], next_page_token="def", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[datastream_resources.ConnectionProfile(),], + next_page_token="ghi", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_connection_profiles(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all( + isinstance(i, datastream_resources.ConnectionProfile) for i in results + ) + + +def test_list_connection_profiles_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_connection_profiles), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + next_page_token="abc", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[], next_page_token="def", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[datastream_resources.ConnectionProfile(),], + next_page_token="ghi", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + ), + RuntimeError, + ) + pages = list(client.list_connection_profiles(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_connection_profiles_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + next_page_token="abc", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[], next_page_token="def", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[datastream_resources.ConnectionProfile(),], + next_page_token="ghi", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_connection_profiles(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, datastream_resources.ConnectionProfile) for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_connection_profiles_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_connection_profiles), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + next_page_token="abc", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[], next_page_token="def", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[datastream_resources.ConnectionProfile(),], + next_page_token="ghi", + ), + datastream.ListConnectionProfilesResponse( + connection_profiles=[ + datastream_resources.ConnectionProfile(), + datastream_resources.ConnectionProfile(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_connection_profiles(request={})).pages: + 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", [datastream.GetConnectionProfileRequest, dict,] +) +def test_get_connection_profile(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.ConnectionProfile( + name="name_value", + display_name="display_name_value", + oracle_profile=datastream_resources.OracleProfile( + hostname="hostname_value" + ), + static_service_ip_connectivity=None, + ) + response = client.get_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.ConnectionProfile) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +def test_get_connection_profile_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 = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + client.get_connection_profile() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetConnectionProfileRequest() + + +@pytest.mark.asyncio +async def test_get_connection_profile_async( + transport: str = "grpc_asyncio", request_type=datastream.GetConnectionProfileRequest +): + client = DatastreamAsyncClient( + 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_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.ConnectionProfile( + name="name_value", display_name="display_name_value", + ) + ) + response = await client.get_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.ConnectionProfile) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +@pytest.mark.asyncio +async def test_get_connection_profile_async_from_dict(): + await test_get_connection_profile_async(request_type=dict) + + +def test_get_connection_profile_field_headers(): + client = DatastreamClient(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 = datastream.GetConnectionProfileRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_connection_profile), "__call__" + ) as call: + call.return_value = datastream_resources.ConnectionProfile() + client.get_connection_profile(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_connection_profile_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.GetConnectionProfileRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_connection_profile), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.ConnectionProfile() + ) + await client.get_connection_profile(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_connection_profile_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.ConnectionProfile() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_connection_profile(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_connection_profile_flattened_error(): + client = DatastreamClient(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_connection_profile( + datastream.GetConnectionProfileRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_connection_profile_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.ConnectionProfile() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.ConnectionProfile() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_connection_profile(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_connection_profile_flattened_error_async(): + client = DatastreamAsyncClient(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_connection_profile( + datastream.GetConnectionProfileRequest(), name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.CreateConnectionProfileRequest, dict,] +) +def test_create_connection_profile(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_connection_profile_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 = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + client.create_connection_profile() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateConnectionProfileRequest() + + +@pytest.mark.asyncio +async def test_create_connection_profile_async( + transport: str = "grpc_asyncio", + request_type=datastream.CreateConnectionProfileRequest, +): + client = DatastreamAsyncClient( + 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_connection_profile), "__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_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_connection_profile_async_from_dict(): + await test_create_connection_profile_async(request_type=dict) + + +def test_create_connection_profile_field_headers(): + client = DatastreamClient(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 = datastream.CreateConnectionProfileRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_connection_profile), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_connection_profile(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_connection_profile_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.CreateConnectionProfileRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_connection_profile), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_connection_profile(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_connection_profile_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_connection_profile), "__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_connection_profile( + parent="parent_value", + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + connection_profile_id="connection_profile_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].connection_profile + mock_val = datastream_resources.ConnectionProfile(name="name_value") + assert arg == mock_val + arg = args[0].connection_profile_id + mock_val = "connection_profile_id_value" + assert arg == mock_val + + +def test_create_connection_profile_flattened_error(): + client = DatastreamClient(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_connection_profile( + datastream.CreateConnectionProfileRequest(), + parent="parent_value", + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + connection_profile_id="connection_profile_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_connection_profile_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_connection_profile), "__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_connection_profile( + parent="parent_value", + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + connection_profile_id="connection_profile_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].connection_profile + mock_val = datastream_resources.ConnectionProfile(name="name_value") + assert arg == mock_val + arg = args[0].connection_profile_id + mock_val = "connection_profile_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_connection_profile_flattened_error_async(): + client = DatastreamAsyncClient(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_connection_profile( + datastream.CreateConnectionProfileRequest(), + parent="parent_value", + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + connection_profile_id="connection_profile_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.UpdateConnectionProfileRequest, dict,] +) +def test_update_connection_profile(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_connection_profile_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 = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + client.update_connection_profile() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateConnectionProfileRequest() + + +@pytest.mark.asyncio +async def test_update_connection_profile_async( + transport: str = "grpc_asyncio", + request_type=datastream.UpdateConnectionProfileRequest, +): + client = DatastreamAsyncClient( + 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_connection_profile), "__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_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_connection_profile_async_from_dict(): + await test_update_connection_profile_async(request_type=dict) + + +def test_update_connection_profile_field_headers(): + client = DatastreamClient(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 = datastream.UpdateConnectionProfileRequest() + + request.connection_profile.name = "connection_profile.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_connection_profile), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_connection_profile(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", + "connection_profile.name=connection_profile.name/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_connection_profile_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.UpdateConnectionProfileRequest() + + request.connection_profile.name = "connection_profile.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_connection_profile), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_connection_profile(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", + "connection_profile.name=connection_profile.name/value", + ) in kw["metadata"] + + +def test_update_connection_profile_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_connection_profile), "__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_connection_profile( + connection_profile=datastream_resources.ConnectionProfile( + 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].connection_profile + mock_val = datastream_resources.ConnectionProfile(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_connection_profile_flattened_error(): + client = DatastreamClient(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_connection_profile( + datastream.UpdateConnectionProfileRequest(), + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_connection_profile_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_connection_profile), "__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_connection_profile( + connection_profile=datastream_resources.ConnectionProfile( + 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].connection_profile + mock_val = datastream_resources.ConnectionProfile(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_connection_profile_flattened_error_async(): + client = DatastreamAsyncClient(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_connection_profile( + datastream.UpdateConnectionProfileRequest(), + connection_profile=datastream_resources.ConnectionProfile( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.DeleteConnectionProfileRequest, dict,] +) +def test_delete_connection_profile(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_connection_profile_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 = DatastreamClient( + 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_connection_profile), "__call__" + ) as call: + client.delete_connection_profile() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteConnectionProfileRequest() + + +@pytest.mark.asyncio +async def test_delete_connection_profile_async( + transport: str = "grpc_asyncio", + request_type=datastream.DeleteConnectionProfileRequest, +): + client = DatastreamAsyncClient( + 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_connection_profile), "__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.delete_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_connection_profile_async_from_dict(): + await test_delete_connection_profile_async(request_type=dict) + + +def test_delete_connection_profile_field_headers(): + client = DatastreamClient(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 = datastream.DeleteConnectionProfileRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_connection_profile), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_connection_profile(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_connection_profile_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.DeleteConnectionProfileRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_connection_profile), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_connection_profile(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_connection_profile_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_connection_profile), "__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.delete_connection_profile(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_connection_profile_flattened_error(): + client = DatastreamClient(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_connection_profile( + datastream.DeleteConnectionProfileRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_connection_profile_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_connection_profile), "__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.delete_connection_profile(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_connection_profile_flattened_error_async(): + client = DatastreamAsyncClient(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_connection_profile( + datastream.DeleteConnectionProfileRequest(), name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.DiscoverConnectionProfileRequest, dict,] +) +def test_discover_connection_profile(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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.discover_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.DiscoverConnectionProfileResponse( + oracle_rdbms=datastream_resources.OracleRdbms( + oracle_schemas=[ + datastream_resources.OracleSchema(schema="schema_value") + ] + ), + ) + response = client.discover_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DiscoverConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.DiscoverConnectionProfileResponse) + + +def test_discover_connection_profile_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 = DatastreamClient( + 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.discover_connection_profile), "__call__" + ) as call: + client.discover_connection_profile() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DiscoverConnectionProfileRequest() + + +@pytest.mark.asyncio +async def test_discover_connection_profile_async( + transport: str = "grpc_asyncio", + request_type=datastream.DiscoverConnectionProfileRequest, +): + client = DatastreamAsyncClient( + 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.discover_connection_profile), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.DiscoverConnectionProfileResponse() + ) + response = await client.discover_connection_profile(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DiscoverConnectionProfileRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.DiscoverConnectionProfileResponse) + + +@pytest.mark.asyncio +async def test_discover_connection_profile_async_from_dict(): + await test_discover_connection_profile_async(request_type=dict) + + +def test_discover_connection_profile_field_headers(): + client = DatastreamClient(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 = datastream.DiscoverConnectionProfileRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.discover_connection_profile), "__call__" + ) as call: + call.return_value = datastream.DiscoverConnectionProfileResponse() + client.discover_connection_profile(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_discover_connection_profile_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.DiscoverConnectionProfileRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.discover_connection_profile), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.DiscoverConnectionProfileResponse() + ) + await client.discover_connection_profile(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"] + + +@pytest.mark.parametrize("request_type", [datastream.ListStreamsRequest, dict,]) +def test_list_streams(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_streams), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamsResponse( + next_page_token="next_page_token_value", unreachable=["unreachable_value"], + ) + response = client.list_streams(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStreamsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_streams_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 = DatastreamClient( + 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_streams), "__call__") as call: + client.list_streams() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamsRequest() + + +@pytest.mark.asyncio +async def test_list_streams_async( + transport: str = "grpc_asyncio", request_type=datastream.ListStreamsRequest +): + client = DatastreamAsyncClient( + 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_streams), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + response = await client.list_streams(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStreamsAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.asyncio +async def test_list_streams_async_from_dict(): + await test_list_streams_async(request_type=dict) + + +def test_list_streams_field_headers(): + client = DatastreamClient(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 = datastream.ListStreamsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_streams), "__call__") as call: + call.return_value = datastream.ListStreamsResponse() + client.list_streams(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_streams_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.ListStreamsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_streams), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamsResponse() + ) + await client.list_streams(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_streams_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_streams), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_streams(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_streams_flattened_error(): + client = DatastreamClient(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_streams( + datastream.ListStreamsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_streams_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_streams), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_streams(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_streams_flattened_error_async(): + client = DatastreamAsyncClient(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_streams( + datastream.ListStreamsRequest(), parent="parent_value", + ) + + +def test_list_streams_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_streams), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamsResponse( + streams=[ + datastream_resources.Stream(), + datastream_resources.Stream(), + datastream_resources.Stream(), + ], + next_page_token="abc", + ), + datastream.ListStreamsResponse(streams=[], next_page_token="def",), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(),], next_page_token="ghi", + ), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(), datastream_resources.Stream(),], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_streams(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, datastream_resources.Stream) for i in results) + + +def test_list_streams_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_streams), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamsResponse( + streams=[ + datastream_resources.Stream(), + datastream_resources.Stream(), + datastream_resources.Stream(), + ], + next_page_token="abc", + ), + datastream.ListStreamsResponse(streams=[], next_page_token="def",), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(),], next_page_token="ghi", + ), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(), datastream_resources.Stream(),], + ), + RuntimeError, + ) + pages = list(client.list_streams(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_streams_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_streams), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamsResponse( + streams=[ + datastream_resources.Stream(), + datastream_resources.Stream(), + datastream_resources.Stream(), + ], + next_page_token="abc", + ), + datastream.ListStreamsResponse(streams=[], next_page_token="def",), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(),], next_page_token="ghi", + ), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(), datastream_resources.Stream(),], + ), + RuntimeError, + ) + async_pager = await client.list_streams(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, datastream_resources.Stream) for i in responses) + + +@pytest.mark.asyncio +async def test_list_streams_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_streams), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamsResponse( + streams=[ + datastream_resources.Stream(), + datastream_resources.Stream(), + datastream_resources.Stream(), + ], + next_page_token="abc", + ), + datastream.ListStreamsResponse(streams=[], next_page_token="def",), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(),], next_page_token="ghi", + ), + datastream.ListStreamsResponse( + streams=[datastream_resources.Stream(), datastream_resources.Stream(),], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_streams(request={})).pages: + 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", [datastream.GetStreamRequest, dict,]) +def test_get_stream(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Stream( + name="name_value", + display_name="display_name_value", + state=datastream_resources.Stream.State.NOT_STARTED, + customer_managed_encryption_key="customer_managed_encryption_key_value", + backfill_all=datastream_resources.Stream.BackfillAllStrategy( + oracle_excluded_objects=datastream_resources.OracleRdbms( + oracle_schemas=[ + datastream_resources.OracleSchema(schema="schema_value") + ] + ) + ), + ) + response = client.get_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.Stream) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == datastream_resources.Stream.State.NOT_STARTED + assert ( + response.customer_managed_encryption_key + == "customer_managed_encryption_key_value" + ) + + +def test_get_stream_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 = DatastreamClient( + 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_stream), "__call__") as call: + client.get_stream() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamRequest() + + +@pytest.mark.asyncio +async def test_get_stream_async( + transport: str = "grpc_asyncio", request_type=datastream.GetStreamRequest +): + client = DatastreamAsyncClient( + 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_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Stream( + name="name_value", + display_name="display_name_value", + state=datastream_resources.Stream.State.NOT_STARTED, + customer_managed_encryption_key="customer_managed_encryption_key_value", + ) + ) + response = await client.get_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.Stream) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == datastream_resources.Stream.State.NOT_STARTED + assert ( + response.customer_managed_encryption_key + == "customer_managed_encryption_key_value" + ) + + +@pytest.mark.asyncio +async def test_get_stream_async_from_dict(): + await test_get_stream_async(request_type=dict) + + +def test_get_stream_field_headers(): + client = DatastreamClient(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 = datastream.GetStreamRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_stream), "__call__") as call: + call.return_value = datastream_resources.Stream() + client.get_stream(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_stream_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.GetStreamRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_stream), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Stream() + ) + await client.get_stream(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_stream_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Stream() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_stream(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_stream_flattened_error(): + client = DatastreamClient(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_stream( + datastream.GetStreamRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_stream_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Stream() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Stream() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_stream(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_stream_flattened_error_async(): + client = DatastreamAsyncClient(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_stream( + datastream.GetStreamRequest(), name="name_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.CreateStreamRequest, dict,]) +def test_create_stream(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_stream_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 = DatastreamClient( + 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_stream), "__call__") as call: + client.create_stream() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateStreamRequest() + + +@pytest.mark.asyncio +async def test_create_stream_async( + transport: str = "grpc_asyncio", request_type=datastream.CreateStreamRequest +): + client = DatastreamAsyncClient( + 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_stream), "__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_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_stream_async_from_dict(): + await test_create_stream_async(request_type=dict) + + +def test_create_stream_field_headers(): + client = DatastreamClient(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 = datastream.CreateStreamRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_stream), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_stream(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_stream_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.CreateStreamRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_stream), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_stream(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_stream_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_stream), "__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_stream( + parent="parent_value", + stream=datastream_resources.Stream(name="name_value"), + stream_id="stream_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].stream + mock_val = datastream_resources.Stream(name="name_value") + assert arg == mock_val + arg = args[0].stream_id + mock_val = "stream_id_value" + assert arg == mock_val + + +def test_create_stream_flattened_error(): + client = DatastreamClient(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_stream( + datastream.CreateStreamRequest(), + parent="parent_value", + stream=datastream_resources.Stream(name="name_value"), + stream_id="stream_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_stream_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_stream), "__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_stream( + parent="parent_value", + stream=datastream_resources.Stream(name="name_value"), + stream_id="stream_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].stream + mock_val = datastream_resources.Stream(name="name_value") + assert arg == mock_val + arg = args[0].stream_id + mock_val = "stream_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_stream_flattened_error_async(): + client = DatastreamAsyncClient(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_stream( + datastream.CreateStreamRequest(), + parent="parent_value", + stream=datastream_resources.Stream(name="name_value"), + stream_id="stream_id_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.UpdateStreamRequest, dict,]) +def test_update_stream(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_stream_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 = DatastreamClient( + 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_stream), "__call__") as call: + client.update_stream() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateStreamRequest() + + +@pytest.mark.asyncio +async def test_update_stream_async( + transport: str = "grpc_asyncio", request_type=datastream.UpdateStreamRequest +): + client = DatastreamAsyncClient( + 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_stream), "__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_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.UpdateStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_stream_async_from_dict(): + await test_update_stream_async(request_type=dict) + + +def test_update_stream_field_headers(): + client = DatastreamClient(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 = datastream.UpdateStreamRequest() + + request.stream.name = "stream.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_stream), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_stream(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", "stream.name=stream.name/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_stream_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.UpdateStreamRequest() + + request.stream.name = "stream.name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_stream), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_stream(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", "stream.name=stream.name/value",) in kw["metadata"] + + +def test_update_stream_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_stream), "__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_stream( + stream=datastream_resources.Stream(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].stream + mock_val = datastream_resources.Stream(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_stream_flattened_error(): + client = DatastreamClient(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_stream( + datastream.UpdateStreamRequest(), + stream=datastream_resources.Stream(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_stream_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_stream), "__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_stream( + stream=datastream_resources.Stream(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].stream + mock_val = datastream_resources.Stream(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_stream_flattened_error_async(): + client = DatastreamAsyncClient(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_stream( + datastream.UpdateStreamRequest(), + stream=datastream_resources.Stream(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize("request_type", [datastream.DeleteStreamRequest, dict,]) +def test_delete_stream(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_stream_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 = DatastreamClient( + 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_stream), "__call__") as call: + client.delete_stream() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteStreamRequest() + + +@pytest.mark.asyncio +async def test_delete_stream_async( + transport: str = "grpc_asyncio", request_type=datastream.DeleteStreamRequest +): + client = DatastreamAsyncClient( + 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_stream), "__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.delete_stream(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteStreamRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_stream_async_from_dict(): + await test_delete_stream_async(request_type=dict) + + +def test_delete_stream_field_headers(): + client = DatastreamClient(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 = datastream.DeleteStreamRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_stream), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_stream(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_stream_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.DeleteStreamRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_stream), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_stream(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_stream_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_stream), "__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.delete_stream(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_stream_flattened_error(): + client = DatastreamClient(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_stream( + datastream.DeleteStreamRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_stream_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_stream), "__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.delete_stream(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_stream_flattened_error_async(): + client = DatastreamAsyncClient(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_stream( + datastream.DeleteStreamRequest(), name="name_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.GetStreamObjectRequest, dict,]) +def test_get_stream_object(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.StreamObject( + name="name_value", display_name="display_name_value", + ) + response = client.get_stream_object(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamObjectRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.StreamObject) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +def test_get_stream_object_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 = DatastreamClient( + 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_stream_object), "__call__" + ) as call: + client.get_stream_object() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamObjectRequest() + + +@pytest.mark.asyncio +async def test_get_stream_object_async( + transport: str = "grpc_asyncio", request_type=datastream.GetStreamObjectRequest +): + client = DatastreamAsyncClient( + 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_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.StreamObject( + name="name_value", display_name="display_name_value", + ) + ) + response = await client.get_stream_object(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetStreamObjectRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.StreamObject) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +@pytest.mark.asyncio +async def test_get_stream_object_async_from_dict(): + await test_get_stream_object_async(request_type=dict) + + +def test_get_stream_object_field_headers(): + client = DatastreamClient(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 = datastream.GetStreamObjectRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stream_object), "__call__" + ) as call: + call.return_value = datastream_resources.StreamObject() + client.get_stream_object(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_stream_object_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.GetStreamObjectRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stream_object), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.StreamObject() + ) + await client.get_stream_object(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_stream_object_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.StreamObject() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_stream_object(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_stream_object_flattened_error(): + client = DatastreamClient(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_stream_object( + datastream.GetStreamObjectRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_stream_object_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.StreamObject() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.StreamObject() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_stream_object(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_stream_object_flattened_error_async(): + client = DatastreamAsyncClient(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_stream_object( + datastream.GetStreamObjectRequest(), name="name_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.LookupStreamObjectRequest, dict,]) +def test_lookup_stream_object(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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.lookup_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.StreamObject( + name="name_value", display_name="display_name_value", + ) + response = client.lookup_stream_object(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.LookupStreamObjectRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.StreamObject) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +def test_lookup_stream_object_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 = DatastreamClient( + 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.lookup_stream_object), "__call__" + ) as call: + client.lookup_stream_object() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.LookupStreamObjectRequest() + + +@pytest.mark.asyncio +async def test_lookup_stream_object_async( + transport: str = "grpc_asyncio", request_type=datastream.LookupStreamObjectRequest +): + client = DatastreamAsyncClient( + 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.lookup_stream_object), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.StreamObject( + name="name_value", display_name="display_name_value", + ) + ) + response = await client.lookup_stream_object(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.LookupStreamObjectRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.StreamObject) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + + +@pytest.mark.asyncio +async def test_lookup_stream_object_async_from_dict(): + await test_lookup_stream_object_async(request_type=dict) + + +def test_lookup_stream_object_field_headers(): + client = DatastreamClient(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 = datastream.LookupStreamObjectRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.lookup_stream_object), "__call__" + ) as call: + call.return_value = datastream_resources.StreamObject() + client.lookup_stream_object(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_lookup_stream_object_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.LookupStreamObjectRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.lookup_stream_object), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.StreamObject() + ) + await client.lookup_stream_object(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"] + + +@pytest.mark.parametrize("request_type", [datastream.ListStreamObjectsRequest, dict,]) +def test_list_stream_objects(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_stream_objects), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamObjectsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_stream_objects(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamObjectsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStreamObjectsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_stream_objects_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 = DatastreamClient( + 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_stream_objects), "__call__" + ) as call: + client.list_stream_objects() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamObjectsRequest() + + +@pytest.mark.asyncio +async def test_list_stream_objects_async( + transport: str = "grpc_asyncio", request_type=datastream.ListStreamObjectsRequest +): + client = DatastreamAsyncClient( + 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_stream_objects), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamObjectsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_stream_objects(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListStreamObjectsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStreamObjectsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_stream_objects_async_from_dict(): + await test_list_stream_objects_async(request_type=dict) + + +def test_list_stream_objects_field_headers(): + client = DatastreamClient(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 = datastream.ListStreamObjectsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), "__call__" + ) as call: + call.return_value = datastream.ListStreamObjectsResponse() + client.list_stream_objects(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_stream_objects_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.ListStreamObjectsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamObjectsResponse() + ) + await client.list_stream_objects(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_stream_objects_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamObjectsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_stream_objects(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_stream_objects_flattened_error(): + client = DatastreamClient(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_stream_objects( + datastream.ListStreamObjectsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_stream_objects_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListStreamObjectsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListStreamObjectsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_stream_objects(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_stream_objects_flattened_error_async(): + client = DatastreamAsyncClient(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_stream_objects( + datastream.ListStreamObjectsRequest(), parent="parent_value", + ) + + +def test_list_stream_objects_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_stream_objects), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + next_page_token="abc", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[], next_page_token="def", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[datastream_resources.StreamObject(),], + next_page_token="ghi", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_stream_objects(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, datastream_resources.StreamObject) for i in results) + + +def test_list_stream_objects_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_stream_objects), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + next_page_token="abc", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[], next_page_token="def", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[datastream_resources.StreamObject(),], + next_page_token="ghi", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + ), + RuntimeError, + ) + pages = list(client.list_stream_objects(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_stream_objects_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + next_page_token="abc", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[], next_page_token="def", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[datastream_resources.StreamObject(),], + next_page_token="ghi", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_stream_objects(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, datastream_resources.StreamObject) for i in responses) + + +@pytest.mark.asyncio +async def test_list_stream_objects_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_stream_objects), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + next_page_token="abc", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[], next_page_token="def", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[datastream_resources.StreamObject(),], + next_page_token="ghi", + ), + datastream.ListStreamObjectsResponse( + stream_objects=[ + datastream_resources.StreamObject(), + datastream_resources.StreamObject(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_stream_objects(request={})).pages: + 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", [datastream.StartBackfillJobRequest, dict,]) +def test_start_backfill_job(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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.start_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StartBackfillJobResponse() + response = client.start_backfill_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StartBackfillJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.StartBackfillJobResponse) + + +def test_start_backfill_job_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 = DatastreamClient( + 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.start_backfill_job), "__call__" + ) as call: + client.start_backfill_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StartBackfillJobRequest() + + +@pytest.mark.asyncio +async def test_start_backfill_job_async( + transport: str = "grpc_asyncio", request_type=datastream.StartBackfillJobRequest +): + client = DatastreamAsyncClient( + 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.start_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StartBackfillJobResponse() + ) + response = await client.start_backfill_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StartBackfillJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.StartBackfillJobResponse) + + +@pytest.mark.asyncio +async def test_start_backfill_job_async_from_dict(): + await test_start_backfill_job_async(request_type=dict) + + +def test_start_backfill_job_field_headers(): + client = DatastreamClient(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 = datastream.StartBackfillJobRequest() + + request.object_ = "object/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.start_backfill_job), "__call__" + ) as call: + call.return_value = datastream.StartBackfillJobResponse() + client.start_backfill_job(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", "object=object/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_start_backfill_job_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.StartBackfillJobRequest() + + request.object_ = "object/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.start_backfill_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StartBackfillJobResponse() + ) + await client.start_backfill_job(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", "object=object/value",) in kw["metadata"] + + +def test_start_backfill_job_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.start_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StartBackfillJobResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.start_backfill_job(object_="object__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].object_ + mock_val = "object__value" + assert arg == mock_val + + +def test_start_backfill_job_flattened_error(): + client = DatastreamClient(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.start_backfill_job( + datastream.StartBackfillJobRequest(), object_="object__value", + ) + + +@pytest.mark.asyncio +async def test_start_backfill_job_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.start_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StartBackfillJobResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StartBackfillJobResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.start_backfill_job(object_="object__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].object_ + mock_val = "object__value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_start_backfill_job_flattened_error_async(): + client = DatastreamAsyncClient(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.start_backfill_job( + datastream.StartBackfillJobRequest(), object_="object__value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.StopBackfillJobRequest, dict,]) +def test_stop_backfill_job(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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.stop_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StopBackfillJobResponse() + response = client.stop_backfill_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StopBackfillJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.StopBackfillJobResponse) + + +def test_stop_backfill_job_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 = DatastreamClient( + 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.stop_backfill_job), "__call__" + ) as call: + client.stop_backfill_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StopBackfillJobRequest() + + +@pytest.mark.asyncio +async def test_stop_backfill_job_async( + transport: str = "grpc_asyncio", request_type=datastream.StopBackfillJobRequest +): + client = DatastreamAsyncClient( + 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.stop_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StopBackfillJobResponse() + ) + response = await client.stop_backfill_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.StopBackfillJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream.StopBackfillJobResponse) + + +@pytest.mark.asyncio +async def test_stop_backfill_job_async_from_dict(): + await test_stop_backfill_job_async(request_type=dict) + + +def test_stop_backfill_job_field_headers(): + client = DatastreamClient(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 = datastream.StopBackfillJobRequest() + + request.object_ = "object/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.stop_backfill_job), "__call__" + ) as call: + call.return_value = datastream.StopBackfillJobResponse() + client.stop_backfill_job(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", "object=object/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_stop_backfill_job_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.StopBackfillJobRequest() + + request.object_ = "object/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.stop_backfill_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StopBackfillJobResponse() + ) + await client.stop_backfill_job(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", "object=object/value",) in kw["metadata"] + + +def test_stop_backfill_job_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.stop_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StopBackfillJobResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.stop_backfill_job(object_="object__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].object_ + mock_val = "object__value" + assert arg == mock_val + + +def test_stop_backfill_job_flattened_error(): + client = DatastreamClient(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.stop_backfill_job( + datastream.StopBackfillJobRequest(), object_="object__value", + ) + + +@pytest.mark.asyncio +async def test_stop_backfill_job_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.stop_backfill_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.StopBackfillJobResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.StopBackfillJobResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.stop_backfill_job(object_="object__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].object_ + mock_val = "object__value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_stop_backfill_job_flattened_error_async(): + client = DatastreamAsyncClient(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.stop_backfill_job( + datastream.StopBackfillJobRequest(), object_="object__value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.FetchStaticIpsRequest, dict,]) +def test_fetch_static_ips(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.FetchStaticIpsResponse( + static_ips=["static_ips_value"], next_page_token="next_page_token_value", + ) + response = client.fetch_static_ips(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.FetchStaticIpsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.FetchStaticIpsPager) + assert response.static_ips == ["static_ips_value"] + assert response.next_page_token == "next_page_token_value" + + +def test_fetch_static_ips_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 = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: + client.fetch_static_ips() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.FetchStaticIpsRequest() + + +@pytest.mark.asyncio +async def test_fetch_static_ips_async( + transport: str = "grpc_asyncio", request_type=datastream.FetchStaticIpsRequest +): + client = DatastreamAsyncClient( + 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.fetch_static_ips), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.FetchStaticIpsResponse( + static_ips=["static_ips_value"], + next_page_token="next_page_token_value", + ) + ) + response = await client.fetch_static_ips(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.FetchStaticIpsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.FetchStaticIpsAsyncPager) + assert response.static_ips == ["static_ips_value"] + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_fetch_static_ips_async_from_dict(): + await test_fetch_static_ips_async(request_type=dict) + + +def test_fetch_static_ips_field_headers(): + client = DatastreamClient(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 = datastream.FetchStaticIpsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.fetch_static_ips), "__call__") as call: + call.return_value = datastream.FetchStaticIpsResponse() + client.fetch_static_ips(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_fetch_static_ips_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.FetchStaticIpsRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.fetch_static_ips), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.FetchStaticIpsResponse() + ) + await client.fetch_static_ips(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_fetch_static_ips_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.fetch_static_ips), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.FetchStaticIpsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.fetch_static_ips(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_fetch_static_ips_flattened_error(): + client = DatastreamClient(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.fetch_static_ips( + datastream.FetchStaticIpsRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_fetch_static_ips_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.fetch_static_ips), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.FetchStaticIpsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.FetchStaticIpsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.fetch_static_ips(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_fetch_static_ips_flattened_error_async(): + client = DatastreamAsyncClient(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.fetch_static_ips( + datastream.FetchStaticIpsRequest(), name="name_value", + ) + + +def test_fetch_static_ips_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.FetchStaticIpsResponse( + static_ips=[str(), str(), str(),], next_page_token="abc", + ), + datastream.FetchStaticIpsResponse(static_ips=[], next_page_token="def",), + datastream.FetchStaticIpsResponse( + static_ips=[str(),], next_page_token="ghi", + ), + datastream.FetchStaticIpsResponse(static_ips=[str(), str(),],), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", ""),)), + ) + pager = client.fetch_static_ips(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, str) for i in results) + + +def test_fetch_static_ips_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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.fetch_static_ips), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.FetchStaticIpsResponse( + static_ips=[str(), str(), str(),], next_page_token="abc", + ), + datastream.FetchStaticIpsResponse(static_ips=[], next_page_token="def",), + datastream.FetchStaticIpsResponse( + static_ips=[str(),], next_page_token="ghi", + ), + datastream.FetchStaticIpsResponse(static_ips=[str(), str(),],), + RuntimeError, + ) + pages = list(client.fetch_static_ips(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_fetch_static_ips_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_static_ips), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.FetchStaticIpsResponse( + static_ips=[str(), str(), str(),], next_page_token="abc", + ), + datastream.FetchStaticIpsResponse(static_ips=[], next_page_token="def",), + datastream.FetchStaticIpsResponse( + static_ips=[str(),], next_page_token="ghi", + ), + datastream.FetchStaticIpsResponse(static_ips=[str(), str(),],), + RuntimeError, + ) + async_pager = await client.fetch_static_ips(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, str) for i in responses) + + +@pytest.mark.asyncio +async def test_fetch_static_ips_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.fetch_static_ips), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.FetchStaticIpsResponse( + static_ips=[str(), str(), str(),], next_page_token="abc", + ), + datastream.FetchStaticIpsResponse(static_ips=[], next_page_token="def",), + datastream.FetchStaticIpsResponse( + static_ips=[str(),], next_page_token="ghi", + ), + datastream.FetchStaticIpsResponse(static_ips=[str(), str(),],), + RuntimeError, + ) + pages = [] + async for page_ in (await client.fetch_static_ips(request={})).pages: + 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", [datastream.CreatePrivateConnectionRequest, dict,] +) +def test_create_private_connection(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreatePrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_private_connection_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 = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + client.create_private_connection() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreatePrivateConnectionRequest() + + +@pytest.mark.asyncio +async def test_create_private_connection_async( + transport: str = "grpc_asyncio", + request_type=datastream.CreatePrivateConnectionRequest, +): + client = DatastreamAsyncClient( + 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_private_connection), "__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_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreatePrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_private_connection_async_from_dict(): + await test_create_private_connection_async(request_type=dict) + + +def test_create_private_connection_field_headers(): + client = DatastreamClient(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 = datastream.CreatePrivateConnectionRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_private_connection), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_private_connection(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_private_connection_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.CreatePrivateConnectionRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_private_connection), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_private_connection(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_private_connection_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_private_connection), "__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_private_connection( + parent="parent_value", + private_connection=datastream_resources.PrivateConnection( + name="name_value" + ), + private_connection_id="private_connection_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].private_connection + mock_val = datastream_resources.PrivateConnection(name="name_value") + assert arg == mock_val + arg = args[0].private_connection_id + mock_val = "private_connection_id_value" + assert arg == mock_val + + +def test_create_private_connection_flattened_error(): + client = DatastreamClient(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_private_connection( + datastream.CreatePrivateConnectionRequest(), + parent="parent_value", + private_connection=datastream_resources.PrivateConnection( + name="name_value" + ), + private_connection_id="private_connection_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_private_connection_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_private_connection), "__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_private_connection( + parent="parent_value", + private_connection=datastream_resources.PrivateConnection( + name="name_value" + ), + private_connection_id="private_connection_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].private_connection + mock_val = datastream_resources.PrivateConnection(name="name_value") + assert arg == mock_val + arg = args[0].private_connection_id + mock_val = "private_connection_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_private_connection_flattened_error_async(): + client = DatastreamAsyncClient(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_private_connection( + datastream.CreatePrivateConnectionRequest(), + parent="parent_value", + private_connection=datastream_resources.PrivateConnection( + name="name_value" + ), + private_connection_id="private_connection_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.GetPrivateConnectionRequest, dict,] +) +def test_get_private_connection(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.PrivateConnection( + name="name_value", + display_name="display_name_value", + state=datastream_resources.PrivateConnection.State.CREATING, + ) + response = client.get_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetPrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.PrivateConnection) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == datastream_resources.PrivateConnection.State.CREATING + + +def test_get_private_connection_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 = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + client.get_private_connection() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetPrivateConnectionRequest() + + +@pytest.mark.asyncio +async def test_get_private_connection_async( + transport: str = "grpc_asyncio", request_type=datastream.GetPrivateConnectionRequest +): + client = DatastreamAsyncClient( + 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_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.PrivateConnection( + name="name_value", + display_name="display_name_value", + state=datastream_resources.PrivateConnection.State.CREATING, + ) + ) + response = await client.get_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetPrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.PrivateConnection) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == datastream_resources.PrivateConnection.State.CREATING + + +@pytest.mark.asyncio +async def test_get_private_connection_async_from_dict(): + await test_get_private_connection_async(request_type=dict) + + +def test_get_private_connection_field_headers(): + client = DatastreamClient(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 = datastream.GetPrivateConnectionRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_private_connection), "__call__" + ) as call: + call.return_value = datastream_resources.PrivateConnection() + client.get_private_connection(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_private_connection_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.GetPrivateConnectionRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_private_connection), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.PrivateConnection() + ) + await client.get_private_connection(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_private_connection_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.PrivateConnection() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_private_connection(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_private_connection_flattened_error(): + client = DatastreamClient(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_private_connection( + datastream.GetPrivateConnectionRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_private_connection_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.PrivateConnection() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.PrivateConnection() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_private_connection(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_private_connection_flattened_error_async(): + client = DatastreamAsyncClient(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_private_connection( + datastream.GetPrivateConnectionRequest(), name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", [datastream.ListPrivateConnectionsRequest, dict,] +) +def test_list_private_connections(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_private_connections), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListPrivateConnectionsResponse( + next_page_token="next_page_token_value", unreachable=["unreachable_value"], + ) + response = client.list_private_connections(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListPrivateConnectionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPrivateConnectionsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_private_connections_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 = DatastreamClient( + 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_private_connections), "__call__" + ) as call: + client.list_private_connections() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListPrivateConnectionsRequest() + + +@pytest.mark.asyncio +async def test_list_private_connections_async( + transport: str = "grpc_asyncio", + request_type=datastream.ListPrivateConnectionsRequest, +): + client = DatastreamAsyncClient( + 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_private_connections), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListPrivateConnectionsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + response = await client.list_private_connections(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListPrivateConnectionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPrivateConnectionsAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.asyncio +async def test_list_private_connections_async_from_dict(): + await test_list_private_connections_async(request_type=dict) + + +def test_list_private_connections_field_headers(): + client = DatastreamClient(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 = datastream.ListPrivateConnectionsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), "__call__" + ) as call: + call.return_value = datastream.ListPrivateConnectionsResponse() + client.list_private_connections(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_private_connections_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.ListPrivateConnectionsRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListPrivateConnectionsResponse() + ) + await client.list_private_connections(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_private_connections_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListPrivateConnectionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_private_connections(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_private_connections_flattened_error(): + client = DatastreamClient(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_private_connections( + datastream.ListPrivateConnectionsRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_private_connections_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListPrivateConnectionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListPrivateConnectionsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_private_connections(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_private_connections_flattened_error_async(): + client = DatastreamAsyncClient(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_private_connections( + datastream.ListPrivateConnectionsRequest(), parent="parent_value", + ) + + +def test_list_private_connections_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_private_connections), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + next_page_token="abc", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[], next_page_token="def", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[datastream_resources.PrivateConnection(),], + next_page_token="ghi", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_private_connections(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all( + isinstance(i, datastream_resources.PrivateConnection) for i in results + ) + + +def test_list_private_connections_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_private_connections), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + next_page_token="abc", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[], next_page_token="def", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[datastream_resources.PrivateConnection(),], + next_page_token="ghi", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + ), + RuntimeError, + ) + pages = list(client.list_private_connections(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_private_connections_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + next_page_token="abc", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[], next_page_token="def", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[datastream_resources.PrivateConnection(),], + next_page_token="ghi", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_private_connections(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, datastream_resources.PrivateConnection) for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_private_connections_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_private_connections), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + next_page_token="abc", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[], next_page_token="def", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[datastream_resources.PrivateConnection(),], + next_page_token="ghi", + ), + datastream.ListPrivateConnectionsResponse( + private_connections=[ + datastream_resources.PrivateConnection(), + datastream_resources.PrivateConnection(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_private_connections(request={})).pages: + 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", [datastream.DeletePrivateConnectionRequest, dict,] +) +def test_delete_private_connection(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeletePrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_private_connection_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 = DatastreamClient( + 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_private_connection), "__call__" + ) as call: + client.delete_private_connection() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeletePrivateConnectionRequest() + + +@pytest.mark.asyncio +async def test_delete_private_connection_async( + transport: str = "grpc_asyncio", + request_type=datastream.DeletePrivateConnectionRequest, +): + client = DatastreamAsyncClient( + 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_private_connection), "__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.delete_private_connection(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeletePrivateConnectionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_private_connection_async_from_dict(): + await test_delete_private_connection_async(request_type=dict) + + +def test_delete_private_connection_field_headers(): + client = DatastreamClient(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 = datastream.DeletePrivateConnectionRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_private_connection), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_private_connection(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_private_connection_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.DeletePrivateConnectionRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_private_connection), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_private_connection(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_private_connection_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_private_connection), "__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.delete_private_connection(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_private_connection_flattened_error(): + client = DatastreamClient(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_private_connection( + datastream.DeletePrivateConnectionRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_private_connection_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_private_connection), "__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.delete_private_connection(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_private_connection_flattened_error_async(): + client = DatastreamAsyncClient(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_private_connection( + datastream.DeletePrivateConnectionRequest(), name="name_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.CreateRouteRequest, dict,]) +def test_create_route(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_route_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 = DatastreamClient( + 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_route), "__call__") as call: + client.create_route() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateRouteRequest() + + +@pytest.mark.asyncio +async def test_create_route_async( + transport: str = "grpc_asyncio", request_type=datastream.CreateRouteRequest +): + client = DatastreamAsyncClient( + 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_route), "__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_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.CreateRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_route_async_from_dict(): + await test_create_route_async(request_type=dict) + + +def test_create_route_field_headers(): + client = DatastreamClient(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 = datastream.CreateRouteRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_route(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_route_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.CreateRouteRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_route), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_route(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_route_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_route), "__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_route( + parent="parent_value", + route=datastream_resources.Route(name="name_value"), + route_id="route_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].route + mock_val = datastream_resources.Route(name="name_value") + assert arg == mock_val + arg = args[0].route_id + mock_val = "route_id_value" + assert arg == mock_val + + +def test_create_route_flattened_error(): + client = DatastreamClient(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_route( + datastream.CreateRouteRequest(), + parent="parent_value", + route=datastream_resources.Route(name="name_value"), + route_id="route_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_route_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_route), "__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_route( + parent="parent_value", + route=datastream_resources.Route(name="name_value"), + route_id="route_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].route + mock_val = datastream_resources.Route(name="name_value") + assert arg == mock_val + arg = args[0].route_id + mock_val = "route_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_route_flattened_error_async(): + client = DatastreamAsyncClient(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_route( + datastream.CreateRouteRequest(), + parent="parent_value", + route=datastream_resources.Route(name="name_value"), + route_id="route_id_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.GetRouteRequest, dict,]) +def test_get_route(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Route( + name="name_value", + display_name="display_name_value", + destination_address="destination_address_value", + destination_port=1734, + ) + response = client.get_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.Route) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.destination_address == "destination_address_value" + assert response.destination_port == 1734 + + +def test_get_route_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 = DatastreamClient( + 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_route), "__call__") as call: + client.get_route() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetRouteRequest() + + +@pytest.mark.asyncio +async def test_get_route_async( + transport: str = "grpc_asyncio", request_type=datastream.GetRouteRequest +): + client = DatastreamAsyncClient( + 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_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Route( + name="name_value", + display_name="display_name_value", + destination_address="destination_address_value", + destination_port=1734, + ) + ) + response = await client.get_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.GetRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, datastream_resources.Route) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.destination_address == "destination_address_value" + assert response.destination_port == 1734 + + +@pytest.mark.asyncio +async def test_get_route_async_from_dict(): + await test_get_route_async(request_type=dict) + + +def test_get_route_field_headers(): + client = DatastreamClient(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 = datastream.GetRouteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_route), "__call__") as call: + call.return_value = datastream_resources.Route() + client.get_route(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_route_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.GetRouteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_route), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Route() + ) + await client.get_route(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_route_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Route() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_route(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_route_flattened_error(): + client = DatastreamClient(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_route( + datastream.GetRouteRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_route_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream_resources.Route() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream_resources.Route() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_route(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_route_flattened_error_async(): + client = DatastreamAsyncClient(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_route( + datastream.GetRouteRequest(), name="name_value", + ) + + +@pytest.mark.parametrize("request_type", [datastream.ListRoutesRequest, dict,]) +def test_list_routes(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListRoutesResponse( + next_page_token="next_page_token_value", unreachable=["unreachable_value"], + ) + response = client.list_routes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListRoutesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListRoutesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +def test_list_routes_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 = DatastreamClient( + 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_routes), "__call__") as call: + client.list_routes() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListRoutesRequest() + + +@pytest.mark.asyncio +async def test_list_routes_async( + transport: str = "grpc_asyncio", request_type=datastream.ListRoutesRequest +): + client = DatastreamAsyncClient( + 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_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListRoutesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + response = await client.list_routes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.ListRoutesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListRoutesAsyncPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.asyncio +async def test_list_routes_async_from_dict(): + await test_list_routes_async(request_type=dict) + + +def test_list_routes_field_headers(): + client = DatastreamClient(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 = datastream.ListRoutesRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_routes), "__call__") as call: + call.return_value = datastream.ListRoutesResponse() + client.list_routes(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_routes_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.ListRoutesRequest() + + request.parent = "parent/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_routes), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListRoutesResponse() + ) + await client.list_routes(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_routes_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListRoutesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_routes(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_routes_flattened_error(): + client = DatastreamClient(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_routes( + datastream.ListRoutesRequest(), parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_routes_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_routes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = datastream.ListRoutesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + datastream.ListRoutesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_routes(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_routes_flattened_error_async(): + client = DatastreamAsyncClient(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_routes( + datastream.ListRoutesRequest(), parent="parent_value", + ) + + +def test_list_routes_pager(transport_name: str = "grpc"): + client = DatastreamClient( + 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_routes), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListRoutesResponse( + routes=[ + datastream_resources.Route(), + datastream_resources.Route(), + datastream_resources.Route(), + ], + next_page_token="abc", + ), + datastream.ListRoutesResponse(routes=[], next_page_token="def",), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(),], next_page_token="ghi", + ), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(), datastream_resources.Route(),], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_routes(request={}) + + assert pager._metadata == metadata + + results = [i for i in pager] + assert len(results) == 6 + assert all(isinstance(i, datastream_resources.Route) for i in results) + + +def test_list_routes_pages(transport_name: str = "grpc"): + client = DatastreamClient( + 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_routes), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListRoutesResponse( + routes=[ + datastream_resources.Route(), + datastream_resources.Route(), + datastream_resources.Route(), + ], + next_page_token="abc", + ), + datastream.ListRoutesResponse(routes=[], next_page_token="def",), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(),], next_page_token="ghi", + ), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(), datastream_resources.Route(),], + ), + RuntimeError, + ) + pages = list(client.list_routes(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_routes_async_pager(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_routes), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListRoutesResponse( + routes=[ + datastream_resources.Route(), + datastream_resources.Route(), + datastream_resources.Route(), + ], + next_page_token="abc", + ), + datastream.ListRoutesResponse(routes=[], next_page_token="def",), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(),], next_page_token="ghi", + ), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(), datastream_resources.Route(),], + ), + RuntimeError, + ) + async_pager = await client.list_routes(request={},) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, datastream_resources.Route) for i in responses) + + +@pytest.mark.asyncio +async def test_list_routes_async_pages(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_routes), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + datastream.ListRoutesResponse( + routes=[ + datastream_resources.Route(), + datastream_resources.Route(), + datastream_resources.Route(), + ], + next_page_token="abc", + ), + datastream.ListRoutesResponse(routes=[], next_page_token="def",), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(),], next_page_token="ghi", + ), + datastream.ListRoutesResponse( + routes=[datastream_resources.Route(), datastream_resources.Route(),], + ), + RuntimeError, + ) + pages = [] + async for page_ in (await client.list_routes(request={})).pages: + 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", [datastream.DeleteRouteRequest, dict,]) +def test_delete_route(request_type, transport: str = "grpc"): + client = DatastreamClient( + 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_route), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_route_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 = DatastreamClient( + 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_route), "__call__") as call: + client.delete_route() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteRouteRequest() + + +@pytest.mark.asyncio +async def test_delete_route_async( + transport: str = "grpc_asyncio", request_type=datastream.DeleteRouteRequest +): + client = DatastreamAsyncClient( + 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_route), "__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.delete_route(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == datastream.DeleteRouteRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_route_async_from_dict(): + await test_delete_route_async(request_type=dict) + + +def test_delete_route_field_headers(): + client = DatastreamClient(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 = datastream.DeleteRouteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_route), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_route(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_route_field_headers_async(): + client = DatastreamAsyncClient(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 = datastream.DeleteRouteRequest() + + request.name = "name/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_route), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_route(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_route_flattened(): + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_route), "__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.delete_route(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_route_flattened_error(): + client = DatastreamClient(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_route( + datastream.DeleteRouteRequest(), name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_route_flattened_async(): + client = DatastreamAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_route), "__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.delete_route(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_route_flattened_error_async(): + client = DatastreamAsyncClient(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_route( + datastream.DeleteRouteRequest(), name="name_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatastreamClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatastreamClient(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 = DatastreamClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = DatastreamClient( + client_options={"scopes": ["1", "2"]}, transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = DatastreamClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.DatastreamGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.DatastreamGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [transports.DatastreamGrpcTransport, transports.DatastreamGrpcAsyncIOTransport,], +) +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() + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = DatastreamClient(credentials=ga_credentials.AnonymousCredentials(),) + assert isinstance(client.transport, transports.DatastreamGrpcTransport,) + + +def test_datastream_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.DatastreamTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_datastream_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.datastream_v1.services.datastream.transports.DatastreamTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.DatastreamTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "list_connection_profiles", + "get_connection_profile", + "create_connection_profile", + "update_connection_profile", + "delete_connection_profile", + "discover_connection_profile", + "list_streams", + "get_stream", + "create_stream", + "update_stream", + "delete_stream", + "get_stream_object", + "lookup_stream_object", + "list_stream_objects", + "start_backfill_job", + "stop_backfill_job", + "fetch_static_ips", + "create_private_connection", + "get_private_connection", + "list_private_connections", + "delete_private_connection", + "create_route", + "get_route", + "list_routes", + "delete_route", + ) + 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 + + +def test_datastream_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.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DatastreamTransport( + 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",), + quota_project_id="octopus", + ) + + +def test_datastream_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.datastream_v1.services.datastream.transports.DatastreamTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.DatastreamTransport() + adc.assert_called_once() + + +def test_datastream_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) + DatastreamClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.DatastreamGrpcTransport, transports.DatastreamGrpcAsyncIOTransport,], +) +def test_datastream_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",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.DatastreamGrpcTransport, grpc_helpers), + (transports.DatastreamGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_datastream_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( + "datastream.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="datastream.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.DatastreamGrpcTransport, transports.DatastreamGrpcAsyncIOTransport], +) +def test_datastream_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_datastream_host_no_port(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="datastream.googleapis.com" + ), + ) + assert client.transport._host == "datastream.googleapis.com:443" + + +def test_datastream_host_with_port(): + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="datastream.googleapis.com:8000" + ), + ) + assert client.transport._host == "datastream.googleapis.com:8000" + + +def test_datastream_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DatastreamGrpcTransport( + 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_datastream_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.DatastreamGrpcAsyncIOTransport( + 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.DatastreamGrpcTransport, transports.DatastreamGrpcAsyncIOTransport], +) +def test_datastream_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.DatastreamGrpcTransport, transports.DatastreamGrpcAsyncIOTransport], +) +def test_datastream_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_datastream_grpc_lro_client(): + client = DatastreamClient( + 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_datastream_grpc_lro_async_client(): + client = DatastreamAsyncClient( + 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_connection_profile_path(): + project = "squid" + location = "clam" + connection_profile = "whelk" + expected = "projects/{project}/locations/{location}/connectionProfiles/{connection_profile}".format( + project=project, location=location, connection_profile=connection_profile, + ) + actual = DatastreamClient.connection_profile_path( + project, location, connection_profile + ) + assert expected == actual + + +def test_parse_connection_profile_path(): + expected = { + "project": "octopus", + "location": "oyster", + "connection_profile": "nudibranch", + } + path = DatastreamClient.connection_profile_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_connection_profile_path(path) + assert expected == actual + + +def test_networks_path(): + project = "cuttlefish" + network = "mussel" + expected = "projects/{project}/global/networks/{network}".format( + project=project, network=network, + ) + actual = DatastreamClient.networks_path(project, network) + assert expected == actual + + +def test_parse_networks_path(): + expected = { + "project": "winkle", + "network": "nautilus", + } + path = DatastreamClient.networks_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_networks_path(path) + assert expected == actual + + +def test_private_connection_path(): + project = "scallop" + location = "abalone" + private_connection = "squid" + expected = "projects/{project}/locations/{location}/privateConnections/{private_connection}".format( + project=project, location=location, private_connection=private_connection, + ) + actual = DatastreamClient.private_connection_path( + project, location, private_connection + ) + assert expected == actual + + +def test_parse_private_connection_path(): + expected = { + "project": "clam", + "location": "whelk", + "private_connection": "octopus", + } + path = DatastreamClient.private_connection_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_private_connection_path(path) + assert expected == actual + + +def test_route_path(): + project = "oyster" + location = "nudibranch" + private_connection = "cuttlefish" + route = "mussel" + expected = "projects/{project}/locations/{location}/privateConnections/{private_connection}/routes/{route}".format( + project=project, + location=location, + private_connection=private_connection, + route=route, + ) + actual = DatastreamClient.route_path(project, location, private_connection, route) + assert expected == actual + + +def test_parse_route_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "private_connection": "scallop", + "route": "abalone", + } + path = DatastreamClient.route_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_route_path(path) + assert expected == actual + + +def test_stream_path(): + project = "squid" + location = "clam" + stream = "whelk" + expected = "projects/{project}/locations/{location}/streams/{stream}".format( + project=project, location=location, stream=stream, + ) + actual = DatastreamClient.stream_path(project, location, stream) + assert expected == actual + + +def test_parse_stream_path(): + expected = { + "project": "octopus", + "location": "oyster", + "stream": "nudibranch", + } + path = DatastreamClient.stream_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_stream_path(path) + assert expected == actual + + +def test_stream_object_path(): + project = "cuttlefish" + location = "mussel" + stream = "winkle" + object = "nautilus" + expected = "projects/{project}/locations/{location}/streams/{stream}/objects/{object}".format( + project=project, location=location, stream=stream, object=object, + ) + actual = DatastreamClient.stream_object_path(project, location, stream, object) + assert expected == actual + + +def test_parse_stream_object_path(): + expected = { + "project": "scallop", + "location": "abalone", + "stream": "squid", + "object": "clam", + } + path = DatastreamClient.stream_object_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_stream_object_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "whelk" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = DatastreamClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "octopus", + } + path = DatastreamClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "oyster" + expected = "folders/{folder}".format(folder=folder,) + actual = DatastreamClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nudibranch", + } + path = DatastreamClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "cuttlefish" + expected = "organizations/{organization}".format(organization=organization,) + actual = DatastreamClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = DatastreamClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "winkle" + expected = "projects/{project}".format(project=project,) + actual = DatastreamClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = DatastreamClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.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 = DatastreamClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = DatastreamClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = DatastreamClient.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.DatastreamTransport, "_prep_wrapped_messages" + ) as prep: + client = DatastreamClient( + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.DatastreamTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = DatastreamClient.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 = DatastreamAsyncClient( + 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 = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = DatastreamClient( + 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 = [ + "grpc", + ] + for transport in transports: + client = DatastreamClient( + 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", + [ + (DatastreamClient, transports.DatastreamGrpcTransport), + (DatastreamAsyncClient, transports.DatastreamGrpcAsyncIOTransport), + ], +) +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, + ) diff --git a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py index 4e7340e..0c32ccb 100644 --- a/tests/unit/gapic/datastream_v1alpha1/test_datastream.py +++ b/tests/unit/gapic/datastream_v1alpha1/test_datastream.py @@ -29,6 +29,7 @@ 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 @@ -501,21 +502,23 @@ def test_datastream_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (DatastreamClient, transports.DatastreamGrpcTransport, "grpc"), + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", grpc_helpers), ( DatastreamAsyncClient, transports.DatastreamGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_datastream_client_client_options_credentials_file( - client_class, transport_class, transport_name + 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) @@ -549,6 +552,67 @@ def test_datastream_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (DatastreamClient, transports.DatastreamGrpcTransport, "grpc", grpc_helpers), + ( + DatastreamAsyncClient, + transports.DatastreamGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_datastream_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, + ) + + # 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( + "datastream.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="datastream.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize( "request_type", [datastream.ListConnectionProfilesRequest, dict,] ) From a7ffab3586ae202090a95090fbdf1297727aa4a1 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 3 Feb 2022 12:52:47 +0000 Subject: [PATCH 11/11] chore(main): release 0.4.0 (#59) :robot: I have created a release *beep* *boop* --- ## [0.4.0](https://github.com/googleapis/python-datastream/compare/v0.3.1...v0.4.0) (2022-02-03) ### Features * add api key support ([#58](https://github.com/googleapis/python-datastream/issues/58)) ([88cf10a](https://github.com/googleapis/python-datastream/commit/88cf10a130116cbc199d6279b00959ad40946671)) * add datastream v1 ([#61](https://github.com/googleapis/python-datastream/issues/61)) ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) ### Bug Fixes * remove `FetchErrorsRequest` and `FetchErrorsResponse` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) * remove `GcsFileFormat` and `SchemaFileFormat` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) * remove `NoConnectivitySettings` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- CHANGELOG.md | 15 +++++++++++++++ setup.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de9514..b2cf1a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [0.4.0](https://github.com/googleapis/python-datastream/compare/v0.3.1...v0.4.0) (2022-02-03) + + +### Features + +* add api key support ([#58](https://github.com/googleapis/python-datastream/issues/58)) ([88cf10a](https://github.com/googleapis/python-datastream/commit/88cf10a130116cbc199d6279b00959ad40946671)) +* add datastream v1 ([#61](https://github.com/googleapis/python-datastream/issues/61)) ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) + + +### Bug Fixes + +* remove `FetchErrorsRequest` and `FetchErrorsResponse` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) +* remove `GcsFileFormat` and `SchemaFileFormat` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) +* remove `NoConnectivitySettings` ([28dab85](https://github.com/googleapis/python-datastream/commit/28dab85bf3b4ad937760d5219623793936e39731)) + ### [0.3.1](https://www.github.com/googleapis/python-datastream/compare/v0.3.0...v0.3.1) (2021-11-01) diff --git a/setup.py b/setup.py index ff77c6d..ececfe8 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-cloud-datastream" description = "Datastream client library" -version = "0.3.1" +version = "0.4.0" release_status = "Development Status :: 3 - Alpha" url = "https://github.com/googleapis/python-datastream" dependencies = [