Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove support for google-api-core<1.26.0 #893

Merged
merged 2 commits into from
May 19, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ except AttributeError:
except pkg_resources.DistributionNotFound: # pragma: NO COVER
_GOOGLE_AUTH_VERSION = None

_API_CORE_VERSION = google.api_core.__version__


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


# TODO(busunkim): These two class methods are in the base transport
# 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-api-core
# and google-auth are increased.
# 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
Expand All @@ -143,25 +140,6 @@ class {{ service.name }}Transport(abc.ABC):

return scopes_kwargs

# TODO: Remove this function once google-api-core >= 1.26.0 is required
@classmethod
def _get_self_signed_jwt_kwargs(cls, host: str, scopes: Optional[Sequence[str]]) -> Dict[str, Union[Optional[Sequence[str]], str]]:
"""Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""

self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {}

if _API_CORE_VERSION and (
packaging.version.parse(_API_CORE_VERSION)
>= packaging.version.parse("1.26.0")
):
self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES
self_signed_jwt_kwargs["scopes"] = scopes
self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST
else:
self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES

return self_signed_jwt_kwargs


def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
and ``credentials_file`` are passed.
"""

self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)

return grpc_helpers.create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
quota_project_id=quota_project_id,
**self_signed_jwt_kwargs,
default_scopes=cls.AUTH_SCOPES,
scopes=scopes,
default_host=cls.DEFAULT_HOST,
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
aio.Channel: A gRPC AsyncIO channel object.
"""

self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)

return grpc_helpers_async.create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
quota_project_id=quota_project_id,
**self_signed_jwt_kwargs,
default_scopes=cls.AUTH_SCOPES,
scopes=scopes,
default_host=cls.DEFAULT_HOST,
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
if self._operations_client is None:
from google.api_core import grpc_helpers

self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(self._host, self._scopes)

self._operations_client = operations_v1.OperationsClient(
grpc_helpers.create_channel(
self._host,
credentials=self._credentials,
**self_signed_jwt_kwargs,
default_scopes=cls.AUTH_SCOPES,
scopes=self._scopes,
default_host=cls.DEFAULT_HOST,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
Expand Down
2 changes: 1 addition & 1 deletion gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ setuptools.setup(
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core[grpc] >= 1.22.2, < 2.0.0dev',
'google-api-core[grpc] >= 1.26.0, < 2.0.0dev',
'libcst >= 0.2.5',
'proto-plus >= 1.15.0',
'packaging >= 14.3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + ser
{% endif %}
from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + service.meta.address.subpackage)|join(".") }}.services.{{ service.name|snake_case }} import transports
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
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
from google.api_core import client_options
from google.api_core import exceptions as core_exceptions
from google.api_core import grpc_helpers
Expand All @@ -55,8 +54,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
{% endfilter %}


# TODO(busunkim): Once google-api-core >= 1.26.0 is required:
# - Delete all the api-core and auth "less than" test cases
# 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"),
Expand All @@ -67,16 +67,6 @@ requires_google_auth_gte_1_25_0 = pytest.mark.skipif(
reason="This test requires google-auth >= 1.25.0",
)

requires_api_core_lt_1_26_0 = pytest.mark.skipif(
packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"),
reason="This test requires google-api-core < 1.26.0",
)

requires_api_core_gte_1_26_0 = pytest.mark.skipif(
packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"),
reason="This test requires google-api-core >= 1.26.0",
)

def client_cert_source_callback():
return b"cert bytes", b"key bytes"

Expand Down Expand Up @@ -1610,7 +1600,6 @@ def test_{{ service.name|snake_case }}_transport_auth_adc_old_google_auth(transp
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
],
)
@requires_api_core_gte_1_26_0
def test_{{ service.name|snake_case }}_transport_create_channel(transport_class, grpc_helpers):
# If credentials and host are not provided, the transport class should use
# ADC credentials.
Expand Down Expand Up @@ -1644,78 +1633,6 @@ def test_{{ service.name|snake_case }}_transport_create_channel(transport_class,
)
{% endwith %}


@pytest.mark.parametrize(
"transport_class,grpc_helpers",
[
(transports.{{ service.name }}GrpcTransport, grpc_helpers),
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
],
)
@requires_api_core_lt_1_26_0
def test_{{ service.name|snake_case }}_transport_create_channel_old_api_core(transport_class, grpc_helpers):
# 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, mock.patch.object(
grpc_helpers, "create_channel", autospec=True
) as create_channel:
creds = ga_credentials.AnonymousCredentials()
adc.return_value = (creds, None)
transport_class(quota_project_id="octopus")

{% with host = (service.host|default('localhost', true)) %}
create_channel.assert_called_with(
"{{ host }}{% if ":" not in service.host %}:443{% endif %}",
credentials=creds,
credentials_file=None,
quota_project_id="octopus",
scopes=(
{% for scope in service.oauth_scopes %}
'{{ scope }}',
{% endfor %}),
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
{% endwith %}


@pytest.mark.parametrize(
"transport_class,grpc_helpers",
[
(transports.{{ service.name }}GrpcTransport, grpc_helpers),
(transports.{{ service.name }}GrpcAsyncIOTransport, grpc_helpers_async)
],
)
@requires_api_core_lt_1_26_0
def test_{{ service.name|snake_case }}_transport_create_channel_user_scopes(transport_class, grpc_helpers):
# 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, mock.patch.object(
grpc_helpers, "create_channel", autospec=True
) as create_channel:
creds = ga_credentials.AnonymousCredentials()
adc.return_value = (creds, None)
{% with host = (service.host|default('localhost', true)) %}

transport_class(quota_project_id="octopus", scopes=["1", "2"])

create_channel.assert_called_with(
"{{ host }}{% if ":" not in service.host %}:443{% endif %}",
credentials=creds,
credentials_file=None,
quota_project_id="octopus",
scopes=["1", "2"],
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
{% endwith %}

{% endif %}

{% if 'grpc' in opts.transport %}
Expand Down