Skip to content

Commit ce558ac

Browse files
authored
fix: remove support for google-api-core<1.26.0 (#893)
1 parent 2afba5a commit ce558ac

File tree

6 files changed

+15
-120
lines changed

6 files changed

+15
-120
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ except AttributeError:
4646
except pkg_resources.DistributionNotFound: # pragma: NO COVER
4747
_GOOGLE_AUTH_VERSION = None
4848

49-
_API_CORE_VERSION = google.api_core.__version__
50-
5149

5250
class {{ service.name }}Transport(abc.ABC):
5351
"""Abstract transport class for {{ service.name }}."""
@@ -121,10 +119,9 @@ class {{ service.name }}Transport(abc.ABC):
121119
self._credentials = credentials
122120

123121

124-
# TODO(busunkim): These two class methods are in the base transport
122+
# TODO(busunkim): This method is in the base transport
125123
# to avoid duplicating code across the transport classes. These functions
126-
# should be deleted once the minimum required versions of google-api-core
127-
# and google-auth are increased.
124+
# should be deleted once the minimum required versions of google-auth is increased.
128125

129126
# TODO: Remove this function once google-auth >= 1.25.0 is required
130127
@classmethod
@@ -143,25 +140,6 @@ class {{ service.name }}Transport(abc.ABC):
143140

144141
return scopes_kwargs
145142

146-
# TODO: Remove this function once google-api-core >= 1.26.0 is required
147-
@classmethod
148-
def _get_self_signed_jwt_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Union[Optional[Sequence[str]], str]]:
149-
"""Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
150-
151-
self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {}
152-
153-
if _API_CORE_VERSION and (
154-
packaging.version.parse(_API_CORE_VERSION)
155-
>= packaging.version.parse("1.26.0")
156-
):
157-
self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES
158-
self_signed_jwt_kwargs["scopes"] = scopes
159-
self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST
160-
else:
161-
self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES
162-
163-
return self_signed_jwt_kwargs
164-
165143

166144
def _prep_wrapped_messages(self, client_info):
167145
# Precompute the wrapped methods.

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
204204
and ``credentials_file`` are passed.
205205
"""
206206

207-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
208-
209207
return grpc_helpers.create_channel(
210208
host,
211209
credentials=credentials,
212210
credentials_file=credentials_file,
213211
quota_project_id=quota_project_id,
214-
**self_signed_jwt_kwargs,
212+
default_scopes=cls.AUTH_SCOPES,
213+
scopes=scopes,
214+
default_host=cls.DEFAULT_HOST,
215215
**kwargs
216216
)
217217

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
7777
aio.Channel: A gRPC AsyncIO channel object.
7878
"""
7979

80-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
81-
8280
return grpc_helpers_async.create_channel(
8381
host,
8482
credentials=credentials,
8583
credentials_file=credentials_file,
8684
quota_project_id=quota_project_id,
87-
**self_signed_jwt_kwargs,
85+
default_scopes=cls.AUTH_SCOPES,
86+
scopes=scopes,
87+
default_host=cls.DEFAULT_HOST,
8888
**kwargs
8989
)
9090

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
109109
if self._operations_client is None:
110110
from google.api_core import grpc_helpers
111111

112-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(self._host, self._scopes)
113-
114112
self._operations_client = operations_v1.OperationsClient(
115113
grpc_helpers.create_channel(
116114
self._host,
117115
credentials=self._credentials,
118-
**self_signed_jwt_kwargs,
116+
default_scopes=cls.AUTH_SCOPES,
117+
scopes=self._scopes,
118+
default_host=cls.DEFAULT_HOST,
119119
options=[
120120
("grpc.max_send_message_length", -1),
121121
("grpc.max_receive_message_length", -1),

gapic/templates/setup.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ setuptools.setup(
2727
platforms='Posix; MacOS X; Windows',
2828
include_package_data=True,
2929
install_requires=(
30-
'google-api-core[grpc] >= 1.22.2, < 2.0.0dev',
30+
'google-api-core[grpc] >= 1.26.0, < 2.0.0dev',
3131
'libcst >= 0.2.5',
3232
'proto-plus >= 1.15.0',
3333
'packaging >= 14.3',

gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + ser
2929
{% endif %}
3030
from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }} import transports
3131
from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.base import _GOOGLE_AUTH_VERSION
32-
from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }}.transports.base import _API_CORE_VERSION
3332
from google.api_core import client_options
3433
from google.api_core import exceptions as core_exceptions
3534
from google.api_core import grpc_helpers
@@ -55,8 +54,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
5554
{% endfilter %}
5655

5756

58-
# TODO(busunkim): Once google-api-core >= 1.26.0 is required:
59-
# - Delete all the api-core and auth "less than" test cases
57+
# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively
58+
# through google-api-core:
59+
# - Delete the auth "less than" test cases
6060
# - Delete these pytest markers (Make the "greater than or equal to" tests the default).
6161
requires_google_auth_lt_1_25_0 = pytest.mark.skipif(
6262
packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"),
@@ -67,16 +67,6 @@ requires_google_auth_gte_1_25_0 = pytest.mark.skipif(
6767
reason="This test requires google-auth >= 1.25.0",
6868
)
6969

70-
requires_api_core_lt_1_26_0 = pytest.mark.skipif(
71-
packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"),
72-
reason="This test requires google-api-core < 1.26.0",
73-
)
74-
75-
requires_api_core_gte_1_26_0 = pytest.mark.skipif(
76-
packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"),
77-
reason="This test requires google-api-core >= 1.26.0",
78-
)
79-
8070
def client_cert_source_callback():
8171
return b"cert bytes", b"key bytes"
8272

@@ -1610,7 +1600,6 @@ def test_{{ service.name|snake_case }}_transport_auth_adc_old_google_auth(transp
16101600
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
16111601
],
16121602
)
1613-
@requires_api_core_gte_1_26_0
16141603
def test_{{ service.name|snake_case }}_transport_create_channel(transport_class, grpc_helpers):
16151604
# If credentials and host are not provided, the transport class should use
16161605
# ADC credentials.
@@ -1644,78 +1633,6 @@ def test_{{ service.name|snake_case }}_transport_create_channel(transport_class,
16441633
)
16451634
{% endwith %}
16461635

1647-
1648-
@pytest.mark.parametrize(
1649-
"transport_class,grpc_helpers",
1650-
[
1651-
(transports.{{ service.name }}GrpcTransport, grpc_helpers),
1652-
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
1653-
],
1654-
)
1655-
@requires_api_core_lt_1_26_0
1656-
def test_{{ service.name|snake_case }}_transport_create_channel_old_api_core(transport_class, grpc_helpers):
1657-
# If credentials and host are not provided, the transport class should use
1658-
# ADC credentials.
1659-
with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object(
1660-
grpc_helpers, "create_channel", autospec=True
1661-
) as create_channel:
1662-
creds = ga_credentials.AnonymousCredentials()
1663-
adc.return_value = (creds, None)
1664-
transport_class(quota_project_id="octopus")
1665-
1666-
{% with host = (service.host|default('localhost', true)) %}
1667-
create_channel.assert_called_with(
1668-
"{{ host }}{% if ":" not in service.host %}:443{% endif %}",
1669-
credentials=creds,
1670-
credentials_file=None,
1671-
quota_project_id="octopus",
1672-
scopes=(
1673-
{% for scope in service.oauth_scopes %}
1674-
'{{ scope }}',
1675-
{% endfor %}),
1676-
ssl_credentials=None,
1677-
options=[
1678-
("grpc.max_send_message_length", -1),
1679-
("grpc.max_receive_message_length", -1),
1680-
],
1681-
)
1682-
{% endwith %}
1683-
1684-
1685-
@pytest.mark.parametrize(
1686-
"transport_class,grpc_helpers",
1687-
[
1688-
(transports.{{ service.name }}GrpcTransport, grpc_helpers),
1689-
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
1690-
],
1691-
)
1692-
@requires_api_core_lt_1_26_0
1693-
def test_{{ service.name|snake_case }}_transport_create_channel_user_scopes(transport_class, grpc_helpers):
1694-
# If credentials and host are not provided, the transport class should use
1695-
# ADC credentials.
1696-
with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch.object(
1697-
grpc_helpers, "create_channel", autospec=True
1698-
) as create_channel:
1699-
creds = ga_credentials.AnonymousCredentials()
1700-
adc.return_value = (creds, None)
1701-
{% with host = (service.host|default('localhost', true)) %}
1702-
1703-
transport_class(quota_project_id="octopus", scopes=["1", "2"])
1704-
1705-
create_channel.assert_called_with(
1706-
"{{ host }}{% if ":" not in service.host %}:443{% endif %}",
1707-
credentials=creds,
1708-
credentials_file=None,
1709-
quota_project_id="octopus",
1710-
scopes=["1", "2"],
1711-
ssl_credentials=None,
1712-
options=[
1713-
("grpc.max_send_message_length", -1),
1714-
("grpc.max_receive_message_length", -1),
1715-
],
1716-
)
1717-
{% endwith %}
1718-
17191636
{% endif %}
17201637

17211638
{% if 'grpc' in opts.transport %}

0 commit comments

Comments
 (0)