Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 56 additions & 14 deletions google/pubsub_v1/services/publisher/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,46 @@ class PublisherAsyncClient:
DEFAULT_ENDPOINT = PublisherClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = PublisherClient.DEFAULT_MTLS_ENDPOINT

subscription_path = staticmethod(PublisherClient.subscription_path)
parse_subscription_path = staticmethod(PublisherClient.parse_subscription_path)
topic_path = staticmethod(PublisherClient.topic_path)
parse_topic_path = staticmethod(PublisherClient.parse_topic_path)

common_billing_account_path = staticmethod(
PublisherClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
PublisherClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(PublisherClient.common_folder_path)
parse_common_folder_path = staticmethod(PublisherClient.parse_common_folder_path)

common_organization_path = staticmethod(PublisherClient.common_organization_path)
parse_common_organization_path = staticmethod(
PublisherClient.parse_common_organization_path
)

common_project_path = staticmethod(PublisherClient.common_project_path)
parse_common_project_path = staticmethod(PublisherClient.parse_common_project_path)

common_location_path = staticmethod(PublisherClient.common_location_path)
parse_common_location_path = staticmethod(
PublisherClient.parse_common_location_path
)

from_service_account_file = PublisherClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> PublisherTransport:
"""Return the transport used by the client instance.

Returns:
PublisherTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(PublisherClient).get_transport_class, type(PublisherClient)
)
Expand Down Expand Up @@ -148,7 +182,8 @@ async def create_topic(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
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."
Expand Down Expand Up @@ -287,7 +322,8 @@ async def publish(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([topic, messages]):
has_flattened_params = any([topic, messages])
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."
Expand All @@ -300,8 +336,9 @@ async def publish(

if topic is not None:
request.topic = topic
if messages is not None:
request.messages = messages

if messages:
request.messages.extend(messages)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand All @@ -312,13 +349,13 @@ async def publish(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Aborted,
exceptions.Cancelled,
exceptions.DeadlineExceeded,
exceptions.InternalServerError,
exceptions.ResourceExhausted,
exceptions.ServiceUnavailable,
exceptions.Unknown,
exceptions.Aborted,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -371,7 +408,8 @@ async def get_topic(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([topic]):
has_flattened_params = any([topic])
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."
Expand All @@ -395,8 +433,8 @@ async def get_topic(
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Aborted,
exceptions.Unknown,
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -453,7 +491,8 @@ async def list_topics(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([project]):
has_flattened_params = any([project])
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."
Expand All @@ -477,8 +516,8 @@ async def list_topics(
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Aborted,
exceptions.Unknown,
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -544,7 +583,8 @@ async def list_topic_subscriptions(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([topic]):
has_flattened_params = any([topic])
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."
Expand All @@ -568,8 +608,8 @@ async def list_topic_subscriptions(
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Aborted,
exceptions.Unknown,
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -639,7 +679,8 @@ async def list_topic_snapshots(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([topic]):
has_flattened_params = any([topic])
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."
Expand All @@ -663,8 +704,8 @@ async def list_topic_snapshots(
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Aborted,
exceptions.Unknown,
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -725,7 +766,8 @@ async def delete_topic(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([topic]):
has_flattened_params = any([topic])
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."
Expand Down
114 changes: 99 additions & 15 deletions google/pubsub_v1/services/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from distutils import util
import os
import re
from typing import Callable, Dict, Sequence, Tuple, Type, Union
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
Expand Down Expand Up @@ -145,6 +145,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

@property
def transport(self) -> PublisherTransport:
"""Return the transport used by the client instance.

Returns:
PublisherTransport: The transport used by the client instance.
"""
return self._transport

@staticmethod
def subscription_path(project: str, subscription: str,) -> str:
"""Return a fully-qualified subscription string."""
return "projects/{project}/subscriptions/{subscription}".format(
project=project, subscription=subscription,
)

@staticmethod
def parse_subscription_path(path: str) -> Dict[str, str]:
"""Parse a subscription path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/subscriptions/(?P<subscription>.+?)$", path
)
return m.groupdict() if m else {}

@staticmethod
def topic_path(project: str, topic: str,) -> str:
"""Return a fully-qualified topic string."""
Expand All @@ -156,12 +180,71 @@ def parse_topic_path(path: str) -> Dict[str, str]:
m = re.match(r"^projects/(?P<project>.+?)/topics/(?P<topic>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Return 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<billing_account>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_folder_path(folder: str,) -> str:
"""Return 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<folder>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_organization_path(organization: str,) -> str:
"""Return 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<organization>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_project_path(project: str,) -> str:
"""Return 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<project>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_location_path(project: str, location: str,) -> str:
"""Return 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<project>.+?)/locations/(?P<location>.+?)$", path)
return m.groupdict() if m else {}

def __init__(
self,
*,
credentials: credentials.Credentials = None,
transport: Union[str, PublisherTransport] = None,
client_options: ClientOptions = None,
credentials: Optional[credentials.Credentials] = None,
transport: Union[str, PublisherTransport, None] = None,
client_options: Optional[client_options_lib.ClientOptions] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the publisher client.
Expand All @@ -176,8 +259,8 @@ def __init__(
transport (Union[str, ~.PublisherTransport]): 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.
client_options (client_options_lib.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:
Expand All @@ -192,20 +275,20 @@ def __init__(
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
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 = ClientOptions.from_dict(client_options)
client_options = client_options_lib.from_dict(client_options)
if client_options is None:
client_options = ClientOptions.ClientOptions()
client_options = client_options_lib.ClientOptions()

# Create SSL credentials for mutual TLS if needed.
use_client_cert = bool(
Expand Down Expand Up @@ -468,8 +551,9 @@ def publish(

if topic is not None:
request.topic = topic
if messages is not None:
request.messages = messages

if messages:
request.messages.extend(messages)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
Expand Down
Loading