Skip to content

Commit 8d33168

Browse files
fix: Allow Protobuf 5.x (#507)
* chore: Update gapic-generator-python to v1.17.1 PiperOrigin-RevId: 629071173 Source-Link: googleapis/googleapis@4afa392 Source-Link: googleapis/googleapis-gen@16dbbb4 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTZkYmJiNGQwNDU3ZGI1ZTYxYWM5Zjk5YjBkNTJhNDYxNTQ0NTVhYyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Update gapic-generator-python to v1.18.0 PiperOrigin-RevId: 638650618 Source-Link: googleapis/googleapis@6330f03 Source-Link: googleapis/googleapis-gen@44fa4f1 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDRmYTRmMTk3OWRjNDVjMTc3OGZkN2NhZjEzZjhlNjFjNmQxY2FlOCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat(spanner): Add support for Cloud Spanner Scheduled Backups PiperOrigin-RevId: 649277844 Source-Link: googleapis/googleapis@fd7efa2 Source-Link: googleapis/googleapis-gen@50be251 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTBiZTI1MTMyOWQ4ZGI1YjU1NTYyNmViZDQ4ODY3MjFmNTQ3ZDNjYyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * allow protobuf 5.x * update constraints --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent f4b23f5 commit 8d33168

File tree

21 files changed

+1075
-192
lines changed

21 files changed

+1075
-192
lines changed

google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from typing import (
2020
Dict,
21+
Callable,
2122
Mapping,
2223
MutableMapping,
2324
MutableSequence,
@@ -37,6 +38,7 @@
3738
from google.auth import credentials as ga_credentials # type: ignore
3839
from google.oauth2 import service_account # type: ignore
3940

41+
4042
try:
4143
OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
4244
except AttributeError: # pragma: NO COVER
@@ -195,7 +197,13 @@ def __init__(
195197
self,
196198
*,
197199
credentials: Optional[ga_credentials.Credentials] = None,
198-
transport: Union[str, ErrorGroupServiceTransport] = "grpc_asyncio",
200+
transport: Optional[
201+
Union[
202+
str,
203+
ErrorGroupServiceTransport,
204+
Callable[..., ErrorGroupServiceTransport],
205+
]
206+
] = "grpc_asyncio",
199207
client_options: Optional[ClientOptions] = None,
200208
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
201209
) -> None:
@@ -207,9 +215,11 @@ def __init__(
207215
credentials identify the application to the service; if none
208216
are specified, the client will attempt to ascertain the
209217
credentials from the environment.
210-
transport (Union[str, ~.ErrorGroupServiceTransport]): The
211-
transport to use. If set to None, a transport is chosen
212-
automatically.
218+
transport (Optional[Union[str,ErrorGroupServiceTransport,Callable[..., ErrorGroupServiceTransport]]]):
219+
The transport to use, or a Callable that constructs and returns a new transport to use.
220+
If a Callable is given, it will be called with the same set of initialization
221+
arguments as used in the ErrorGroupServiceTransport constructor.
222+
If set to None, a transport is chosen automatically.
213223
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
214224
Custom options for the client.
215225
@@ -318,16 +328,19 @@ async def sample_get_group():
318328
319329
"""
320330
# Create or coerce a protobuf request object.
321-
# Quick check: If we got a request object, we should *not* have
322-
# gotten any keyword arguments that map to the request.
331+
# - Quick check: If we got a request object, we should *not* have
332+
# gotten any keyword arguments that map to the request.
323333
has_flattened_params = any([group_name])
324334
if request is not None and has_flattened_params:
325335
raise ValueError(
326336
"If the `request` argument is set, then none of "
327337
"the individual field arguments should be set."
328338
)
329339

330-
request = error_group_service.GetGroupRequest(request)
340+
# - Use the request object if provided (there's no risk of modifying the input as
341+
# there are no flattened fields), or create one.
342+
if not isinstance(request, error_group_service.GetGroupRequest):
343+
request = error_group_service.GetGroupRequest(request)
331344

332345
# If we have keyword arguments corresponding to fields on the
333346
# request, apply these.
@@ -336,11 +349,9 @@ async def sample_get_group():
336349

337350
# Wrap the RPC method; this adds retry and timeout information,
338351
# and friendly error handling.
339-
rpc = gapic_v1.method_async.wrap_method(
340-
self._client._transport.get_group,
341-
default_timeout=None,
342-
client_info=DEFAULT_CLIENT_INFO,
343-
)
352+
rpc = self._client._transport._wrapped_methods[
353+
self._client._transport.get_group
354+
]
344355

345356
# Certain fields should be provided within the metadata header;
346357
# add these here.
@@ -425,16 +436,19 @@ async def sample_update_group():
425436
426437
"""
427438
# Create or coerce a protobuf request object.
428-
# Quick check: If we got a request object, we should *not* have
429-
# gotten any keyword arguments that map to the request.
439+
# - Quick check: If we got a request object, we should *not* have
440+
# gotten any keyword arguments that map to the request.
430441
has_flattened_params = any([group])
431442
if request is not None and has_flattened_params:
432443
raise ValueError(
433444
"If the `request` argument is set, then none of "
434445
"the individual field arguments should be set."
435446
)
436447

437-
request = error_group_service.UpdateGroupRequest(request)
448+
# - Use the request object if provided (there's no risk of modifying the input as
449+
# there are no flattened fields), or create one.
450+
if not isinstance(request, error_group_service.UpdateGroupRequest):
451+
request = error_group_service.UpdateGroupRequest(request)
438452

439453
# If we have keyword arguments corresponding to fields on the
440454
# request, apply these.
@@ -443,11 +457,9 @@ async def sample_update_group():
443457

444458
# Wrap the RPC method; this adds retry and timeout information,
445459
# and friendly error handling.
446-
rpc = gapic_v1.method_async.wrap_method(
447-
self._client._transport.update_group,
448-
default_timeout=None,
449-
client_info=DEFAULT_CLIENT_INFO,
450-
)
460+
rpc = self._client._transport._wrapped_methods[
461+
self._client._transport.update_group
462+
]
451463

452464
# Certain fields should be provided within the metadata header;
453465
# add these here.

google/cloud/errorreporting_v1beta1/services/error_group_service/client.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from typing import (
2020
Dict,
21+
Callable,
2122
Mapping,
2223
MutableMapping,
2324
MutableSequence,
@@ -523,7 +524,13 @@ def __init__(
523524
self,
524525
*,
525526
credentials: Optional[ga_credentials.Credentials] = None,
526-
transport: Optional[Union[str, ErrorGroupServiceTransport]] = None,
527+
transport: Optional[
528+
Union[
529+
str,
530+
ErrorGroupServiceTransport,
531+
Callable[..., ErrorGroupServiceTransport],
532+
]
533+
] = None,
527534
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
528535
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
529536
) -> None:
@@ -535,9 +542,11 @@ def __init__(
535542
credentials identify the application to the service; if none
536543
are specified, the client will attempt to ascertain the
537544
credentials from the environment.
538-
transport (Union[str, ErrorGroupServiceTransport]): The
539-
transport to use. If set to None, a transport is chosen
540-
automatically.
545+
transport (Optional[Union[str,ErrorGroupServiceTransport,Callable[..., ErrorGroupServiceTransport]]]):
546+
The transport to use, or a Callable that constructs and returns a new transport.
547+
If a Callable is given, it will be called with the same set of initialization
548+
arguments as used in the ErrorGroupServiceTransport constructor.
549+
If set to None, a transport is chosen automatically.
541550
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
542551
Custom options for the client.
543552
@@ -646,8 +655,16 @@ def __init__(
646655
api_key_value
647656
)
648657

649-
Transport = type(self).get_transport_class(cast(str, transport))
650-
self._transport = Transport(
658+
transport_init: Union[
659+
Type[ErrorGroupServiceTransport],
660+
Callable[..., ErrorGroupServiceTransport],
661+
] = (
662+
type(self).get_transport_class(transport)
663+
if isinstance(transport, str) or transport is None
664+
else cast(Callable[..., ErrorGroupServiceTransport], transport)
665+
)
666+
# initialize with the provided callable or the passed in class
667+
self._transport = transport_init(
651668
credentials=credentials,
652669
credentials_file=self._client_options.credentials_file,
653670
host=self._api_endpoint,
@@ -724,19 +741,17 @@ def sample_get_group():
724741
725742
"""
726743
# Create or coerce a protobuf request object.
727-
# Quick check: If we got a request object, we should *not* have
728-
# gotten any keyword arguments that map to the request.
744+
# - Quick check: If we got a request object, we should *not* have
745+
# gotten any keyword arguments that map to the request.
729746
has_flattened_params = any([group_name])
730747
if request is not None and has_flattened_params:
731748
raise ValueError(
732749
"If the `request` argument is set, then none of "
733750
"the individual field arguments should be set."
734751
)
735752

736-
# Minor optimization to avoid making a copy if the user passes
737-
# in a error_group_service.GetGroupRequest.
738-
# There's no risk of modifying the input as we've already verified
739-
# there are no flattened fields.
753+
# - Use the request object if provided (there's no risk of modifying the input as
754+
# there are no flattened fields), or create one.
740755
if not isinstance(request, error_group_service.GetGroupRequest):
741756
request = error_group_service.GetGroupRequest(request)
742757
# If we have keyword arguments corresponding to fields on the
@@ -831,19 +846,17 @@ def sample_update_group():
831846
832847
"""
833848
# Create or coerce a protobuf request object.
834-
# Quick check: If we got a request object, we should *not* have
835-
# gotten any keyword arguments that map to the request.
849+
# - Quick check: If we got a request object, we should *not* have
850+
# gotten any keyword arguments that map to the request.
836851
has_flattened_params = any([group])
837852
if request is not None and has_flattened_params:
838853
raise ValueError(
839854
"If the `request` argument is set, then none of "
840855
"the individual field arguments should be set."
841856
)
842857

843-
# Minor optimization to avoid making a copy if the user passes
844-
# in a error_group_service.UpdateGroupRequest.
845-
# There's no risk of modifying the input as we've already verified
846-
# there are no flattened fields.
858+
# - Use the request object if provided (there's no risk of modifying the input as
859+
# there are no flattened fields), or create one.
847860
if not isinstance(request, error_group_service.UpdateGroupRequest):
848861
request = error_group_service.UpdateGroupRequest(request)
849862
# If we have keyword arguments corresponding to fields on the

google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def __init__(
8383

8484
# Save the scopes.
8585
self._scopes = scopes
86+
if not hasattr(self, "_ignore_credentials"):
87+
self._ignore_credentials: bool = False
8688

8789
# If no credentials are provided, then determine the appropriate
8890
# defaults.
@@ -95,7 +97,7 @@ def __init__(
9597
credentials, _ = google.auth.load_credentials_from_file(
9698
credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
9799
)
98-
elif credentials is None:
100+
elif credentials is None and not self._ignore_credentials:
99101
credentials, _ = google.auth.default(
100102
**scopes_kwargs, quota_project_id=quota_project_id
101103
)

google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
credentials: Optional[ga_credentials.Credentials] = None,
5252
credentials_file: Optional[str] = None,
5353
scopes: Optional[Sequence[str]] = None,
54-
channel: Optional[grpc.Channel] = None,
54+
channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None,
5555
api_mtls_endpoint: Optional[str] = None,
5656
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
5757
ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
@@ -71,14 +71,17 @@ def __init__(
7171
credentials identify the application to the service; if none
7272
are specified, the client will attempt to ascertain the
7373
credentials from the environment.
74-
This argument is ignored if ``channel`` is provided.
74+
This argument is ignored if a ``channel`` instance is provided.
7575
credentials_file (Optional[str]): A file with credentials that can
7676
be loaded with :func:`google.auth.load_credentials_from_file`.
77-
This argument is ignored if ``channel`` is provided.
77+
This argument is ignored if a ``channel`` instance is provided.
7878
scopes (Optional(Sequence[str])): A list of scopes. This argument is
79-
ignored if ``channel`` is provided.
80-
channel (Optional[grpc.Channel]): A ``Channel`` instance through
81-
which to make calls.
79+
ignored if a ``channel`` instance is provided.
80+
channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]):
81+
A ``Channel`` instance through which to make calls, or a Callable
82+
that constructs and returns one. If set to None, ``self.create_channel``
83+
is used to create the channel. If a Callable is given, it will be called
84+
with the same arguments as used in ``self.create_channel``.
8285
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
8386
If provided, it overrides the ``host`` argument and tries to create
8487
a mutual TLS channel with client SSL credentials from
@@ -88,11 +91,11 @@ def __init__(
8891
private key bytes, both in PEM format. It is ignored if
8992
``api_mtls_endpoint`` is None.
9093
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
91-
for the grpc channel. It is ignored if ``channel`` is provided.
94+
for the grpc channel. It is ignored if a ``channel`` instance is provided.
9295
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
9396
A callback to provide client certificate bytes and private key bytes,
9497
both in PEM format. It is used to configure a mutual TLS channel. It is
95-
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
98+
ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
9699
quota_project_id (Optional[str]): An optional project to use for billing
97100
and quota.
98101
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
@@ -118,9 +121,10 @@ def __init__(
118121
if client_cert_source:
119122
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
120123

121-
if channel:
124+
if isinstance(channel, grpc.Channel):
122125
# Ignore credentials if a channel was passed.
123-
credentials = False
126+
credentials = None
127+
self._ignore_credentials = True
124128
# If a channel was explicitly provided, set it.
125129
self._grpc_channel = channel
126130
self._ssl_channel_credentials = None
@@ -159,7 +163,9 @@ def __init__(
159163
)
160164

161165
if not self._grpc_channel:
162-
self._grpc_channel = type(self).create_channel(
166+
# initialize with the provided callable or the default channel
167+
channel_init = channel or type(self).create_channel
168+
self._grpc_channel = channel_init(
163169
self._host,
164170
# use the credentials which are saved
165171
credentials=self._credentials,

0 commit comments

Comments
 (0)