Skip to content

Commit

Permalink
chore: regenerate GAPIC layer with latest changes (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut authored Apr 2, 2021
1 parent f5eee4b commit 469ebaa
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 639 deletions.
2 changes: 1 addition & 1 deletion .kokoro/test-samples-against-head.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2021 Google LLC
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions google/pubsub_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@
"ModifyPushConfigRequest",
"PublishRequest",
"PublishResponse",
"PublisherClient",
"PubsubMessage",
"PullRequest",
"PullResponse",
"PushConfig",
"ReceivedMessage",
"RetryPolicy",
"Schema",
"SchemaServiceClient",
"SchemaSettings",
"SchemaView",
"SeekRequest",
Expand All @@ -135,5 +135,5 @@
"ValidateMessageResponse",
"ValidateSchemaRequest",
"ValidateSchemaResponse",
"SchemaServiceClient",
"PublisherClient",
)
9 changes: 9 additions & 0 deletions google/pubsub_v1/services/publisher/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async def create_topic(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -293,6 +294,7 @@ async def update_topic(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -390,6 +392,7 @@ async def publish(
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -470,6 +473,7 @@ async def get_topic(
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -554,6 +558,7 @@ async def list_topics(
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -647,6 +652,7 @@ async def list_topic_subscriptions(
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -744,6 +750,7 @@ async def list_topic_snapshots(
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -828,6 +835,7 @@ async def delete_topic(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down Expand Up @@ -888,6 +896,7 @@ async def detach_subscription(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=DEFAULT_CLIENT_INFO,
Expand Down
27 changes: 18 additions & 9 deletions google/pubsub_v1/services/publisher/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ def __init__(
scope (Optional[Sequence[str]]): A list of scopes.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
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.
"""
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
host += ":443"
self._host = host

# Save the scopes.
self._scopes = scopes or self.AUTH_SCOPES

# If no credentials are provided, then determine the appropriate
# defaults.
if credentials and credentials_file:
Expand All @@ -95,20 +98,17 @@ def __init__(

if credentials_file is not None:
credentials, _ = auth.load_credentials_from_file(
credentials_file, scopes=scopes, quota_project_id=quota_project_id
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
)

elif credentials is None:
credentials, _ = auth.default(
scopes=scopes, quota_project_id=quota_project_id
scopes=self._scopes, quota_project_id=quota_project_id
)

# Save the credentials.
self._credentials = credentials

# Lifted into its own function so it can be stubbed out during tests.
self._prep_wrapped_messages(client_info)

def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
Expand All @@ -119,6 +119,7 @@ def _prep_wrapped_messages(self, client_info):
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -130,6 +131,7 @@ def _prep_wrapped_messages(self, client_info):
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -149,6 +151,7 @@ def _prep_wrapped_messages(self, client_info):
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -164,6 +167,7 @@ def _prep_wrapped_messages(self, client_info):
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -179,6 +183,7 @@ def _prep_wrapped_messages(self, client_info):
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -194,6 +199,7 @@ def _prep_wrapped_messages(self, client_info):
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -209,6 +215,7 @@ def _prep_wrapped_messages(self, client_info):
exceptions.ServiceUnavailable,
exceptions.Unknown,
),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -220,6 +227,7 @@ def _prep_wrapped_messages(self, client_info):
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand All @@ -231,6 +239,7 @@ def _prep_wrapped_messages(self, client_info):
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(exceptions.ServiceUnavailable,),
deadline=60.0,
),
default_timeout=60.0,
client_info=client_info,
Expand Down
102 changes: 37 additions & 65 deletions google/pubsub_v1/services/publisher/transports/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,79 +110,60 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._grpc_channel = None
self._ssl_channel_credentials = ssl_channel_credentials
self._stubs: Dict[str, Callable] = {}

if api_mtls_endpoint:
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
if client_cert_source:
warnings.warn("client_cert_source is deprecated", DeprecationWarning)

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
# Ignore credentials if a channel was passed.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
host = (
api_mtls_endpoint
if ":" in api_mtls_endpoint
else api_mtls_endpoint + ":443"
)

if credentials is None:
credentials, _ = auth.default(
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
)

# Create SSL credentials with client_cert_source or application
# default SSL credentials.
if client_cert_source:
cert, key = client_cert_source()
ssl_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
else:
ssl_credentials = SslCredentials().ssl_credentials

# create a new channel. The provided one is ignored.
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
("grpc.keepalive_time_ms", 30000),
],
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"
if api_mtls_endpoint:
host = api_mtls_endpoint

# Create SSL credentials with client_cert_source or application
# default SSL credentials.
if client_cert_source:
cert, key = client_cert_source()
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
else:
self._ssl_channel_credentials = SslCredentials().ssl_credentials

if credentials is None:
credentials, _ = auth.default(
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
)
else:
if client_cert_source_for_mtls and not ssl_channel_credentials:
cert, key = client_cert_source_for_mtls()
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)

if client_cert_source_for_mtls and not ssl_channel_credentials:
cert, key = client_cert_source_for_mtls()
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
# The base transport sets the host, credentials and scopes
super().__init__(
host=host,
credentials=credentials,
credentials_file=credentials_file,
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
)

# create a new channel. The provided one is ignored.
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
self._host,
credentials=self._credentials,
credentials_file=credentials_file,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
Expand All @@ -191,17 +172,8 @@ def __init__(
],
)

self._stubs = {} # type: Dict[str, Callable]

# Run the base constructor.
super().__init__(
host=host,
credentials=credentials,
credentials_file=credentials_file,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
client_info=client_info,
)
# Wrap messages. This must be done after self._grpc_channel exists
self._prep_wrapped_messages(client_info)

@classmethod
def create_channel(
Expand All @@ -215,7 +187,7 @@ def create_channel(
) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
address (Optional[str]): The host for the channel to use.
host (Optional[str]): The host for the channel to use.
credentials (Optional[~.Credentials]): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
Expand Down
Loading

0 comments on commit 469ebaa

Please sign in to comment.