From 290b9c5615eaa03674b773a27b756483abd76195 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:28:12 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#530) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../services/publisher/async_client.py | 64 +++++------ google/pubsub_v1/services/publisher/client.py | 26 ++--- .../services/publisher/transports/base.py | 35 +----- .../publisher/transports/grpc_asyncio.py | 1 - .../services/schema_service/async_client.py | 46 ++++---- .../services/schema_service/client.py | 20 ++-- .../schema_service/transports/base.py | 35 +----- .../schema_service/transports/grpc_asyncio.py | 1 - .../services/subscriber/async_client.py | 102 +++++++++--------- .../pubsub_v1/services/subscriber/client.py | 40 +++---- .../services/subscriber/transports/base.py | 35 +----- .../subscriber/transports/grpc_asyncio.py | 1 - google/pubsub_v1/types/pubsub.py | 12 +++ google/pubsub_v1/types/schema.py | 9 ++ setup.py | 3 +- testing/constraints-3.6.txt | 4 +- tests/unit/gapic/pubsub_v1/test_publisher.py | 95 ++-------------- .../gapic/pubsub_v1/test_schema_service.py | 100 ++--------------- tests/unit/gapic/pubsub_v1/test_subscriber.py | 95 ++-------------- 19 files changed, 208 insertions(+), 516 deletions(-) diff --git a/google/pubsub_v1/services/publisher/async_client.py b/google/pubsub_v1/services/publisher/async_client.py index 25753d0cf..e835ae7b7 100644 --- a/google/pubsub_v1/services/publisher/async_client.py +++ b/google/pubsub_v1/services/publisher/async_client.py @@ -19,7 +19,7 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +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 @@ -27,6 +27,8 @@ from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -168,10 +170,10 @@ def __init__( async def create_topic( self, - request: pubsub.Topic = None, + request: Union[pubsub.Topic, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: @@ -180,7 +182,7 @@ async def create_topic( (https://cloud.google.com/pubsub/docs/admin#resource_names). Args: - request (:class:`google.pubsub_v1.types.Topic`): + request (Union[google.pubsub_v1.types.Topic, dict]): The request object. A topic resource. name (:class:`str`): Required. The name of the topic. It must have the format @@ -254,9 +256,9 @@ async def create_topic( async def update_topic( self, - request: pubsub.UpdateTopicRequest = None, + request: Union[pubsub.UpdateTopicRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: @@ -264,7 +266,7 @@ async def update_topic( properties of a topic are not modifiable. Args: - request (:class:`google.pubsub_v1.types.UpdateTopicRequest`): + request (Union[google.pubsub_v1.types.UpdateTopicRequest, dict]): The request object. Request for the UpdateTopic method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -313,11 +315,11 @@ async def update_topic( async def publish( self, - request: pubsub.PublishRequest = None, + request: Union[pubsub.PublishRequest, dict] = None, *, topic: str = None, messages: Sequence[pubsub.PubsubMessage] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.PublishResponse: @@ -325,7 +327,7 @@ async def publish( the topic does not exist. Args: - request (:class:`google.pubsub_v1.types.PublishRequest`): + request (Union[google.pubsub_v1.types.PublishRequest, dict]): The request object. Request for the Publish method. topic (:class:`str`): Required. The messages in the request will be published @@ -407,17 +409,17 @@ async def publish( async def get_topic( self, - request: pubsub.GetTopicRequest = None, + request: Union[pubsub.GetTopicRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: r"""Gets the configuration of a topic. Args: - request (:class:`google.pubsub_v1.types.GetTopicRequest`): + request (Union[google.pubsub_v1.types.GetTopicRequest, dict]): The request object. Request for the GetTopic method. topic (:class:`str`): Required. The name of the topic to get. Format is @@ -487,17 +489,17 @@ async def get_topic( async def list_topics( self, - request: pubsub.ListTopicsRequest = None, + request: Union[pubsub.ListTopicsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicsAsyncPager: r"""Lists matching topics. Args: - request (:class:`google.pubsub_v1.types.ListTopicsRequest`): + request (Union[google.pubsub_v1.types.ListTopicsRequest, dict]): The request object. Request for the `ListTopics` method. project (:class:`str`): Required. The name of the project in which to list @@ -577,10 +579,10 @@ async def list_topics( async def list_topic_subscriptions( self, - request: pubsub.ListTopicSubscriptionsRequest = None, + request: Union[pubsub.ListTopicSubscriptionsRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicSubscriptionsAsyncPager: @@ -588,7 +590,7 @@ async def list_topic_subscriptions( topic. Args: - request (:class:`google.pubsub_v1.types.ListTopicSubscriptionsRequest`): + request (Union[google.pubsub_v1.types.ListTopicSubscriptionsRequest, dict]): The request object. Request for the `ListTopicSubscriptions` method. topic (:class:`str`): @@ -670,10 +672,10 @@ async def list_topic_subscriptions( async def list_topic_snapshots( self, - request: pubsub.ListTopicSnapshotsRequest = None, + request: Union[pubsub.ListTopicSnapshotsRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicSnapshotsAsyncPager: @@ -685,7 +687,7 @@ async def list_topic_snapshots( in an existing subscription to the state captured by a snapshot. Args: - request (:class:`google.pubsub_v1.types.ListTopicSnapshotsRequest`): + request (Union[google.pubsub_v1.types.ListTopicSnapshotsRequest, dict]): The request object. Request for the `ListTopicSnapshots` method. topic (:class:`str`): @@ -767,10 +769,10 @@ async def list_topic_snapshots( async def delete_topic( self, - request: pubsub.DeleteTopicRequest = None, + request: Union[pubsub.DeleteTopicRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -782,7 +784,7 @@ async def delete_topic( field is set to ``_deleted-topic_``. Args: - request (:class:`google.pubsub_v1.types.DeleteTopicRequest`): + request (Union[google.pubsub_v1.types.DeleteTopicRequest, dict]): The request object. Request for the `DeleteTopic` method. topic (:class:`str`): @@ -846,9 +848,9 @@ async def delete_topic( async def detach_subscription( self, - request: pubsub.DetachSubscriptionRequest = None, + request: Union[pubsub.DetachSubscriptionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.DetachSubscriptionResponse: @@ -859,7 +861,7 @@ async def detach_subscription( will stop. Args: - request (:class:`google.pubsub_v1.types.DetachSubscriptionRequest`): + request (Union[google.pubsub_v1.types.DetachSubscriptionRequest, dict]): The request object. Request for the DetachSubscription method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -913,7 +915,7 @@ async def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1022,7 +1024,7 @@ async def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1132,7 +1134,7 @@ async def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/publisher/client.py b/google/pubsub_v1/services/publisher/client.py index 7075e8fcd..604d58411 100644 --- a/google/pubsub_v1/services/publisher/client.py +++ b/google/pubsub_v1/services/publisher/client.py @@ -32,6 +32,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -407,7 +409,7 @@ def create_topic( request: Union[pubsub.Topic, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: @@ -484,7 +486,7 @@ def update_topic( self, request: Union[pubsub.UpdateTopicRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: @@ -538,7 +540,7 @@ def publish( *, topic: str = None, messages: Sequence[pubsub.PubsubMessage] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.PublishResponse: @@ -617,7 +619,7 @@ def get_topic( request: Union[pubsub.GetTopicRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Topic: @@ -687,7 +689,7 @@ def list_topics( request: Union[pubsub.ListTopicsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicsPager: @@ -767,7 +769,7 @@ def list_topic_subscriptions( request: Union[pubsub.ListTopicSubscriptionsRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicSubscriptionsPager: @@ -850,7 +852,7 @@ def list_topic_snapshots( request: Union[pubsub.ListTopicSnapshotsRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTopicSnapshotsPager: @@ -937,7 +939,7 @@ def delete_topic( request: Union[pubsub.DeleteTopicRequest, dict] = None, *, topic: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1007,7 +1009,7 @@ def detach_subscription( self, request: Union[pubsub.DetachSubscriptionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.DetachSubscriptionResponse: @@ -1078,7 +1080,7 @@ def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1191,7 +1193,7 @@ def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1305,7 +1307,7 @@ def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: TimeoutType = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/publisher/transports/base.py b/google/pubsub_v1/services/publisher/transports/base.py index b794d5965..02740aa4e 100644 --- a/google/pubsub_v1/services/publisher/transports/base.py +++ b/google/pubsub_v1/services/publisher/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -40,15 +39,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class PublisherTransport(abc.ABC): """Abstract transport class for Publisher.""" @@ -101,7 +91,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -134,29 +124,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py b/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py index 7c896a252..67c59c79a 100644 --- a/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py +++ b/google/pubsub_v1/services/publisher/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/pubsub_v1/services/schema_service/async_client.py b/google/pubsub_v1/services/schema_service/async_client.py index df10c2a8d..b77639f34 100644 --- a/google/pubsub_v1/services/schema_service/async_client.py +++ b/google/pubsub_v1/services/schema_service/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +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.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.pubsub_v1.services.schema_service import pagers @@ -166,19 +168,19 @@ def __init__( async def create_schema( self, - request: gp_schema.CreateSchemaRequest = None, + request: Union[gp_schema.CreateSchemaRequest, dict] = None, *, parent: str = None, schema: gp_schema.Schema = None, schema_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gp_schema.Schema: r"""Creates a schema. Args: - request (:class:`google.pubsub_v1.types.CreateSchemaRequest`): + request (Union[google.pubsub_v1.types.CreateSchemaRequest, dict]): The request object. Request for the CreateSchema method. parent (:class:`str`): Required. The name of the project in which to create the @@ -261,17 +263,17 @@ async def create_schema( async def get_schema( self, - request: schema.GetSchemaRequest = None, + request: Union[schema.GetSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> schema.Schema: r"""Gets a schema. Args: - request (:class:`google.pubsub_v1.types.GetSchemaRequest`): + request (Union[google.pubsub_v1.types.GetSchemaRequest, dict]): The request object. Request for the GetSchema method. name (:class:`str`): Required. The name of the schema to get. Format is @@ -329,17 +331,17 @@ async def get_schema( async def list_schemas( self, - request: schema.ListSchemasRequest = None, + request: Union[schema.ListSchemasRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSchemasAsyncPager: r"""Lists schemas in a project. Args: - request (:class:`google.pubsub_v1.types.ListSchemasRequest`): + request (Union[google.pubsub_v1.types.ListSchemasRequest, dict]): The request object. Request for the `ListSchemas` method. parent (:class:`str`): @@ -408,17 +410,17 @@ async def list_schemas( async def delete_schema( self, - request: schema.DeleteSchemaRequest = None, + request: Union[schema.DeleteSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a schema. Args: - request (:class:`google.pubsub_v1.types.DeleteSchemaRequest`): + request (Union[google.pubsub_v1.types.DeleteSchemaRequest, dict]): The request object. Request for the `DeleteSchema` method. name (:class:`str`): @@ -472,18 +474,18 @@ async def delete_schema( async def validate_schema( self, - request: gp_schema.ValidateSchemaRequest = None, + request: Union[gp_schema.ValidateSchemaRequest, dict] = None, *, parent: str = None, schema: gp_schema.Schema = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gp_schema.ValidateSchemaResponse: r"""Validates a schema. Args: - request (:class:`google.pubsub_v1.types.ValidateSchemaRequest`): + request (Union[google.pubsub_v1.types.ValidateSchemaRequest, dict]): The request object. Request for the `ValidateSchema` method. parent (:class:`str`): @@ -553,16 +555,16 @@ async def validate_schema( async def validate_message( self, - request: schema.ValidateMessageRequest = None, + request: Union[schema.ValidateMessageRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> schema.ValidateMessageResponse: r"""Validates a message against a schema. Args: - request (:class:`google.pubsub_v1.types.ValidateMessageRequest`): + request (Union[google.pubsub_v1.types.ValidateMessageRequest, dict]): The request object. Request for the `ValidateMessage` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -604,7 +606,7 @@ async def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -712,7 +714,7 @@ async def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -821,7 +823,7 @@ async def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/schema_service/client.py b/google/pubsub_v1/services/schema_service/client.py index 66c63a803..22efb1512 100644 --- a/google/pubsub_v1/services/schema_service/client.py +++ b/google/pubsub_v1/services/schema_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.pubsub_v1.services.schema_service import pagers @@ -352,7 +354,7 @@ def create_schema( parent: str = None, schema: gp_schema.Schema = None, schema_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gp_schema.Schema: @@ -445,7 +447,7 @@ def get_schema( request: Union[schema.GetSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> schema.Schema: @@ -513,7 +515,7 @@ def list_schemas( request: Union[schema.ListSchemasRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSchemasPager: @@ -592,7 +594,7 @@ def delete_schema( request: Union[schema.DeleteSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -657,7 +659,7 @@ def validate_schema( *, parent: str = None, schema: gp_schema.Schema = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gp_schema.ValidateSchemaResponse: @@ -736,7 +738,7 @@ def validate_message( self, request: Union[schema.ValidateMessageRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> schema.ValidateMessageResponse: @@ -799,7 +801,7 @@ def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -907,7 +909,7 @@ def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1016,7 +1018,7 @@ def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/schema_service/transports/base.py b/google/pubsub_v1/services/schema_service/transports/base.py index bcc50f011..96e9f44c8 100644 --- a/google/pubsub_v1/services/schema_service/transports/base.py +++ b/google/pubsub_v1/services/schema_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -41,15 +40,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SchemaServiceTransport(abc.ABC): """Abstract transport class for SchemaService.""" @@ -102,7 +92,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -135,29 +125,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py b/google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py index 8b9205f84..120214bf0 100644 --- a/google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py +++ b/google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/pubsub_v1/services/subscriber/async_client.py b/google/pubsub_v1/services/subscriber/async_client.py index 4e918daed..0a55f4bd5 100644 --- a/google/pubsub_v1/services/subscriber/async_client.py +++ b/google/pubsub_v1/services/subscriber/async_client.py @@ -29,13 +29,15 @@ import warnings import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +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.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -179,13 +181,13 @@ def __init__( async def create_subscription( self, - request: pubsub.Subscription = None, + request: Union[pubsub.Subscription, dict] = None, *, name: str = None, topic: str = None, push_config: pubsub.PushConfig = None, ack_deadline_seconds: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: @@ -204,7 +206,7 @@ async def create_subscription( request. Args: - request (:class:`google.pubsub_v1.types.Subscription`): + request (Union[google.pubsub_v1.types.Subscription, dict]): The request object. A subscription resource. name (:class:`str`): Required. The name of the subscription. It must have the @@ -334,17 +336,17 @@ async def create_subscription( async def get_subscription( self, - request: pubsub.GetSubscriptionRequest = None, + request: Union[pubsub.GetSubscriptionRequest, dict] = None, *, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: r"""Gets the configuration details of a subscription. Args: - request (:class:`google.pubsub_v1.types.GetSubscriptionRequest`): + request (Union[google.pubsub_v1.types.GetSubscriptionRequest, dict]): The request object. Request for the GetSubscription method. subscription (:class:`str`): @@ -416,9 +418,9 @@ async def get_subscription( async def update_subscription( self, - request: pubsub.UpdateSubscriptionRequest = None, + request: Union[pubsub.UpdateSubscriptionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: @@ -427,7 +429,7 @@ async def update_subscription( modifiable. Args: - request (:class:`google.pubsub_v1.types.UpdateSubscriptionRequest`): + request (Union[google.pubsub_v1.types.UpdateSubscriptionRequest, dict]): The request object. Request for the UpdateSubscription method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -476,17 +478,17 @@ async def update_subscription( async def list_subscriptions( self, - request: pubsub.ListSubscriptionsRequest = None, + request: Union[pubsub.ListSubscriptionsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSubscriptionsAsyncPager: r"""Lists matching subscriptions. Args: - request (:class:`google.pubsub_v1.types.ListSubscriptionsRequest`): + request (Union[google.pubsub_v1.types.ListSubscriptionsRequest, dict]): The request object. Request for the `ListSubscriptions` method. project (:class:`str`): @@ -566,10 +568,10 @@ async def list_subscriptions( async def delete_subscription( self, - request: pubsub.DeleteSubscriptionRequest = None, + request: Union[pubsub.DeleteSubscriptionRequest, dict] = None, *, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -581,7 +583,7 @@ async def delete_subscription( topic unless the same topic is specified. Args: - request (:class:`google.pubsub_v1.types.DeleteSubscriptionRequest`): + request (Union[google.pubsub_v1.types.DeleteSubscriptionRequest, dict]): The request object. Request for the DeleteSubscription method. subscription (:class:`str`): @@ -646,12 +648,12 @@ async def delete_subscription( async def modify_ack_deadline( self, - request: pubsub.ModifyAckDeadlineRequest = None, + request: Union[pubsub.ModifyAckDeadlineRequest, dict] = None, *, subscription: str = None, ack_ids: Sequence[str] = None, ack_deadline_seconds: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -663,7 +665,7 @@ async def modify_ack_deadline( used for subsequent messages. Args: - request (:class:`google.pubsub_v1.types.ModifyAckDeadlineRequest`): + request (Union[google.pubsub_v1.types.ModifyAckDeadlineRequest, dict]): The request object. Request for the ModifyAckDeadline method. subscription (:class:`str`): @@ -753,11 +755,11 @@ async def modify_ack_deadline( async def acknowledge( self, - request: pubsub.AcknowledgeRequest = None, + request: Union[pubsub.AcknowledgeRequest, dict] = None, *, subscription: str = None, ack_ids: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -771,7 +773,7 @@ async def acknowledge( error. Args: - request (:class:`google.pubsub_v1.types.AcknowledgeRequest`): + request (Union[google.pubsub_v1.types.AcknowledgeRequest, dict]): The request object. Request for the Acknowledge method. subscription (:class:`str`): Required. The subscription whose message is being @@ -846,12 +848,12 @@ async def acknowledge( async def pull( self, - request: pubsub.PullRequest = None, + request: Union[pubsub.PullRequest, dict] = None, *, subscription: str = None, return_immediately: bool = None, max_messages: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.PullResponse: @@ -860,7 +862,7 @@ async def pull( pending for the given subscription. Args: - request (:class:`google.pubsub_v1.types.PullRequest`): + request (Union[google.pubsub_v1.types.PullRequest, dict]): The request object. Request for the `Pull` method. subscription (:class:`str`): Required. The subscription from which messages should be @@ -968,7 +970,7 @@ def streaming_pull( self, requests: AsyncIterator[pubsub.StreamingPullRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[pubsub.StreamingPullResponse]]: @@ -1030,11 +1032,11 @@ def streaming_pull( async def modify_push_config( self, - request: pubsub.ModifyPushConfigRequest = None, + request: Union[pubsub.ModifyPushConfigRequest, dict] = None, *, subscription: str = None, push_config: pubsub.PushConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1047,7 +1049,7 @@ async def modify_push_config( call regardless of changes to the ``PushConfig``. Args: - request (:class:`google.pubsub_v1.types.ModifyPushConfigRequest`): + request (Union[google.pubsub_v1.types.ModifyPushConfigRequest, dict]): The request object. Request for the ModifyPushConfig method. subscription (:class:`str`): @@ -1126,10 +1128,10 @@ async def modify_push_config( async def get_snapshot( self, - request: pubsub.GetSnapshotRequest = None, + request: Union[pubsub.GetSnapshotRequest, dict] = None, *, snapshot: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1142,7 +1144,7 @@ async def get_snapshot( subscription to the state captured by a snapshot. Args: - request (:class:`google.pubsub_v1.types.GetSnapshotRequest`): + request (Union[google.pubsub_v1.types.GetSnapshotRequest, dict]): The request object. Request for the GetSnapshot method. snapshot (:class:`str`): Required. The name of the snapshot to get. Format is @@ -1217,10 +1219,10 @@ async def get_snapshot( async def list_snapshots( self, - request: pubsub.ListSnapshotsRequest = None, + request: Union[pubsub.ListSnapshotsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSnapshotsAsyncPager: @@ -1231,7 +1233,7 @@ async def list_snapshots( in an existing subscription to the state captured by a snapshot. Args: - request (:class:`google.pubsub_v1.types.ListSnapshotsRequest`): + request (Union[google.pubsub_v1.types.ListSnapshotsRequest, dict]): The request object. Request for the `ListSnapshots` method. project (:class:`str`): @@ -1311,11 +1313,11 @@ async def list_snapshots( async def create_snapshot( self, - request: pubsub.CreateSnapshotRequest = None, + request: Union[pubsub.CreateSnapshotRequest, dict] = None, *, name: str = None, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1340,7 +1342,7 @@ async def create_snapshot( request. Args: - request (:class:`google.pubsub_v1.types.CreateSnapshotRequest`): + request (Union[google.pubsub_v1.types.CreateSnapshotRequest, dict]): The request object. Request for the `CreateSnapshot` method. name (:class:`str`): @@ -1436,9 +1438,9 @@ async def create_snapshot( async def update_snapshot( self, - request: pubsub.UpdateSnapshotRequest = None, + request: Union[pubsub.UpdateSnapshotRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1451,7 +1453,7 @@ async def update_snapshot( snapshot. Args: - request (:class:`google.pubsub_v1.types.UpdateSnapshotRequest`): + request (Union[google.pubsub_v1.types.UpdateSnapshotRequest, dict]): The request object. Request for the UpdateSnapshot method. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1506,10 +1508,10 @@ async def update_snapshot( async def delete_snapshot( self, - request: pubsub.DeleteSnapshotRequest = None, + request: Union[pubsub.DeleteSnapshotRequest, dict] = None, *, snapshot: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1525,7 +1527,7 @@ async def delete_snapshot( the same subscription is specified. Args: - request (:class:`google.pubsub_v1.types.DeleteSnapshotRequest`): + request (Union[google.pubsub_v1.types.DeleteSnapshotRequest, dict]): The request object. Request for the `DeleteSnapshot` method. snapshot (:class:`str`): @@ -1588,9 +1590,9 @@ async def delete_snapshot( async def seek( self, - request: pubsub.SeekRequest = None, + request: Union[pubsub.SeekRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.SeekResponse: @@ -1605,7 +1607,7 @@ async def seek( same topic. Args: - request (:class:`google.pubsub_v1.types.SeekRequest`): + request (Union[google.pubsub_v1.types.SeekRequest, dict]): The request object. Request for the `Seek` method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. @@ -1657,7 +1659,7 @@ async def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1765,7 +1767,7 @@ async def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1874,7 +1876,7 @@ async def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/subscriber/client.py b/google/pubsub_v1/services/subscriber/client.py index e8bb6df66..c6f9b2d9f 100644 --- a/google/pubsub_v1/services/subscriber/client.py +++ b/google/pubsub_v1/services/subscriber/client.py @@ -32,6 +32,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.iam.v1 import iam_policy_pb2 # type: ignore from google.iam.v1 import policy_pb2 # type: ignore from google.protobuf import duration_pb2 # type: ignore @@ -412,7 +414,7 @@ def create_subscription( topic: str = None, push_config: pubsub.PushConfig = None, ack_deadline_seconds: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: @@ -554,7 +556,7 @@ def get_subscription( request: Union[pubsub.GetSubscriptionRequest, dict] = None, *, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: @@ -625,7 +627,7 @@ def update_subscription( self, request: Union[pubsub.UpdateSubscriptionRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Subscription: @@ -679,7 +681,7 @@ def list_subscriptions( request: Union[pubsub.ListSubscriptionsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSubscriptionsPager: @@ -759,7 +761,7 @@ def delete_subscription( request: Union[pubsub.DeleteSubscriptionRequest, dict] = None, *, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -833,7 +835,7 @@ def modify_ack_deadline( subscription: str = None, ack_ids: Sequence[str] = None, ack_deadline_seconds: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -931,7 +933,7 @@ def acknowledge( *, subscription: str = None, ack_ids: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1017,7 +1019,7 @@ def pull( subscription: str = None, return_immediately: bool = None, max_messages: int = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.PullResponse: @@ -1124,7 +1126,7 @@ def streaming_pull( self, requests: Iterator[pubsub.StreamingPullRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[pubsub.StreamingPullResponse]: @@ -1179,7 +1181,7 @@ def modify_push_config( *, subscription: str = None, push_config: pubsub.PushConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1266,7 +1268,7 @@ def get_snapshot( request: Union[pubsub.GetSnapshotRequest, dict] = None, *, snapshot: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1347,7 +1349,7 @@ def list_snapshots( request: Union[pubsub.ListSnapshotsRequest, dict] = None, *, project: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSnapshotsPager: @@ -1432,7 +1434,7 @@ def create_snapshot( *, name: str = None, subscription: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1547,7 +1549,7 @@ def update_snapshot( self, request: Union[pubsub.UpdateSnapshotRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.Snapshot: @@ -1611,7 +1613,7 @@ def delete_snapshot( request: Union[pubsub.DeleteSnapshotRequest, dict] = None, *, snapshot: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1684,7 +1686,7 @@ def seek( self, request: Union[pubsub.SeekRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pubsub.SeekResponse: @@ -1755,7 +1757,7 @@ def set_iam_policy( self, request: iam_policy_pb2.SetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1867,7 +1869,7 @@ def get_iam_policy( self, request: iam_policy_pb2.GetIamPolicyRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> policy_pb2.Policy: @@ -1980,7 +1982,7 @@ def test_iam_permissions( self, request: iam_policy_pb2.TestIamPermissionsRequest = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> iam_policy_pb2.TestIamPermissionsResponse: diff --git a/google/pubsub_v1/services/subscriber/transports/base.py b/google/pubsub_v1/services/subscriber/transports/base.py index c39d8fcc8..57b671400 100644 --- a/google/pubsub_v1/services/subscriber/transports/base.py +++ b/google/pubsub_v1/services/subscriber/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -40,15 +39,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SubscriberTransport(abc.ABC): """Abstract transport class for Subscriber.""" @@ -101,7 +91,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -134,29 +124,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py b/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py index ff822071f..5d5149b8b 100644 --- a/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py +++ b/google/pubsub_v1/services/subscriber/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/pubsub_v1/types/pubsub.py b/google/pubsub_v1/types/pubsub.py index 913e845be..1a8e8b00f 100644 --- a/google/pubsub_v1/types/pubsub.py +++ b/google/pubsub_v1/types/pubsub.py @@ -692,6 +692,8 @@ class ExpirationPolicy(proto.Message): class PushConfig(proto.Message): r"""Configuration for a push delivery endpoint. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: push_endpoint (str): A URL locating the endpoint to which messages should be @@ -731,6 +733,7 @@ class PushConfig(proto.Message): If specified, Pub/Sub will generate and attach an OIDC JWT token as an ``Authorization`` header in the HTTP request for every pushed message. + This field is a member of `oneof`_ ``authentication_method``. """ class OidcToken(proto.Message): @@ -1282,6 +1285,13 @@ class DeleteSnapshotRequest(proto.Message): class SeekRequest(proto.Message): r"""Request for the ``Seek`` method. + 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: subscription (str): Required. The subscription to affect. @@ -1299,10 +1309,12 @@ class SeekRequest(proto.Message): subscription creation time), only retained messages will be marked as unacknowledged, and already-expunged messages will not be restored. + This field is a member of `oneof`_ ``target``. snapshot (str): The snapshot to seek to. The snapshot's topic must be the same as that of the provided subscription. Format is ``projects/{project}/snapshots/{snap}``. + This field is a member of `oneof`_ ``target``. """ subscription = proto.Field(proto.STRING, number=1,) diff --git a/google/pubsub_v1/types/schema.py b/google/pubsub_v1/types/schema.py index 4f7777fbc..6d1821ecd 100644 --- a/google/pubsub_v1/types/schema.py +++ b/google/pubsub_v1/types/schema.py @@ -202,6 +202,13 @@ class ValidateSchemaResponse(proto.Message): class ValidateMessageRequest(proto.Message): r"""Request for the ``ValidateMessage`` method. + 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 name of the project in which to validate @@ -210,8 +217,10 @@ class ValidateMessageRequest(proto.Message): Name of the schema against which to validate. Format is ``projects/{project}/schemas/{schema}``. + This field is a member of `oneof`_ ``schema_spec``. schema (google.pubsub_v1.types.Schema): Ad-hoc schema against which to validate + This field is a member of `oneof`_ ``schema_spec``. message (bytes): Message to validate against the provided ``schema_spec``. encoding (google.pubsub_v1.types.Encoding): diff --git a/setup.py b/setup.py index 9749aea2e..4fedbb7f8 100644 --- a/setup.py +++ b/setup.py @@ -33,11 +33,10 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "libcst >= 0.3.10", "proto-plus >= 1.7.1", "grpc-google-iam-v1 >= 0.12.3, < 0.13dev", - "packaging >= 14.3", ] extras = {} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 73677dc23..b89267633 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,9 +5,7 @@ # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 grpcio==1.38.1 -google-api-core==1.26.0 +google-api-core==1.28.0 libcst==0.3.10 proto-plus==1.7.1 grpc-google-iam-v1==0.12.3 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-api-core diff --git a/tests/unit/gapic/pubsub_v1/test_publisher.py b/tests/unit/gapic/pubsub_v1/test_publisher.py index 457c00640..58291d280 100644 --- a/tests/unit/gapic/pubsub_v1/test_publisher.py +++ b/tests/unit/gapic/pubsub_v1/test_publisher.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,26 +42,11 @@ from google.pubsub_v1.services.publisher import PublisherClient from google.pubsub_v1.services.publisher import pagers from google.pubsub_v1.services.publisher import transports -from google.pubsub_v1.services.publisher.transports.base import _GOOGLE_AUTH_VERSION from google.pubsub_v1.types import pubsub from google.pubsub_v1.types import schema import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -206,7 +190,7 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -223,7 +207,7 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -240,7 +224,7 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -269,7 +253,7 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -326,7 +310,7 @@ def test_publisher_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -368,7 +352,7 @@ def test_publisher_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -390,7 +374,7 @@ def test_publisher_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -421,7 +405,7 @@ def test_publisher_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -452,7 +436,7 @@ def test_publisher_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -2650,7 +2634,6 @@ def test_publisher_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_publisher_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2674,29 +2657,6 @@ def test_publisher_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_publisher_base_transport_with_credentials_file_old_google_auth(): - # 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.pubsub_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PublisherTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - def test_publisher_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( @@ -2708,7 +2668,6 @@ def test_publisher_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_publisher_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2724,26 +2683,10 @@ def test_publisher_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_publisher_auth_adc_old_google_auth(): - # 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) - PublisherClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.PublisherGrpcTransport, transports.PublisherGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_publisher_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2760,26 +2703,6 @@ def test_publisher_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.PublisherGrpcTransport, transports.PublisherGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_publisher_transport_auth_adc_old_google_auth(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") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/pubsub_v1/test_schema_service.py b/tests/unit/gapic/pubsub_v1/test_schema_service.py index a3002ca6c..009124440 100644 --- a/tests/unit/gapic/pubsub_v1/test_schema_service.py +++ b/tests/unit/gapic/pubsub_v1/test_schema_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -40,28 +39,11 @@ from google.pubsub_v1.services.schema_service import SchemaServiceClient from google.pubsub_v1.services.schema_service import pagers from google.pubsub_v1.services.schema_service import transports -from google.pubsub_v1.services.schema_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.pubsub_v1.types import schema from google.pubsub_v1.types import schema as gp_schema import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -218,7 +200,7 @@ def test_schema_service_client_client_options( 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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -235,7 +217,7 @@ def test_schema_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -252,7 +234,7 @@ def test_schema_service_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -281,7 +263,7 @@ def test_schema_service_client_client_options( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -340,7 +322,7 @@ def test_schema_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -382,7 +364,7 @@ def test_schema_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -404,7 +386,7 @@ def test_schema_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -435,7 +417,7 @@ def test_schema_service_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -466,7 +448,7 @@ def test_schema_service_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -1902,7 +1884,6 @@ def test_schema_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_schema_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1926,29 +1907,6 @@ def test_schema_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_schema_service_base_transport_with_credentials_file_old_google_auth(): - # 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.pubsub_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SchemaServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - def test_schema_service_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( @@ -1960,7 +1918,6 @@ def test_schema_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_schema_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1976,21 +1933,6 @@ def test_schema_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_schema_service_auth_adc_old_google_auth(): - # 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) - SchemaServiceClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1998,7 +1940,6 @@ def test_schema_service_auth_adc_old_google_auth(): transports.SchemaServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_schema_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2015,29 +1956,6 @@ def test_schema_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SchemaServiceGrpcTransport, - transports.SchemaServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_schema_service_transport_auth_adc_old_google_auth(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") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/pubsub_v1/test_subscriber.py b/tests/unit/gapic/pubsub_v1/test_subscriber.py index 9d760c68e..78ed2e926 100644 --- a/tests/unit/gapic/pubsub_v1/test_subscriber.py +++ b/tests/unit/gapic/pubsub_v1/test_subscriber.py @@ -16,7 +16,6 @@ import os import mock import warnings -import packaging.version import grpc from grpc.experimental import aio @@ -44,25 +43,10 @@ from google.pubsub_v1.services.subscriber import SubscriberClient from google.pubsub_v1.services.subscriber import pagers from google.pubsub_v1.services.subscriber import transports -from google.pubsub_v1.services.subscriber.transports.base import _GOOGLE_AUTH_VERSION from google.pubsub_v1.types import pubsub import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -210,7 +194,7 @@ def test_subscriber_client_client_options( 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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -227,7 +211,7 @@ def test_subscriber_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,7 +228,7 @@ def test_subscriber_client_client_options( 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() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -273,7 +257,7 @@ def test_subscriber_client_client_options( 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) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -330,7 +314,7 @@ def test_subscriber_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -372,7 +356,7 @@ def test_subscriber_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -394,7 +378,7 @@ def test_subscriber_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -425,7 +409,7 @@ def test_subscriber_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -456,7 +440,7 @@ def test_subscriber_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(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -3926,7 +3910,6 @@ def test_subscriber_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_subscriber_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3950,29 +3933,6 @@ def test_subscriber_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_subscriber_base_transport_with_credentials_file_old_google_auth(): - # 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.pubsub_v1.services.subscriber.transports.SubscriberTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SubscriberTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - def test_subscriber_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( @@ -3984,7 +3944,6 @@ def test_subscriber_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_subscriber_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -4000,26 +3959,10 @@ def test_subscriber_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_subscriber_auth_adc_old_google_auth(): - # 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) - SubscriberClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.SubscriberGrpcTransport, transports.SubscriberGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_subscriber_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -4036,26 +3979,6 @@ def test_subscriber_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.SubscriberGrpcTransport, transports.SubscriberGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_subscriber_transport_auth_adc_old_google_auth(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") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [