Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
chore: use gapic-generator-python 0.53.4 (#78)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

docs: list oneofs in docstring
fix(deps): require google-api-core >= 1.28.0
fix(deps): drop packaging dependency

committer: busunkim96@
PiperOrigin-RevId: 406468269

Source-Link: googleapis/googleapis@83d81b0

Source-Link: googleapis/googleapis-gen@2ff001f
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9
  • Loading branch information
gcf-owl-bot[bot] committed Nov 1, 2021
1 parent 4e20b00 commit 8df5c2c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 124 deletions.
Expand Up @@ -19,13 +19,15 @@
from typing import Dict, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core.client_options import ClientOptions # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

OptionalRetry = Union[retries.Retry, object]

from google.cloud.policytroubleshooter_v1.types import checker
from google.cloud.policytroubleshooter_v1.types import explanations
from .transports.base import IamCheckerTransport, DEFAULT_CLIENT_INFO
Expand Down Expand Up @@ -158,9 +160,9 @@ def __init__(

async def troubleshoot_iam_policy(
self,
request: checker.TroubleshootIamPolicyRequest = None,
request: Union[checker.TroubleshootIamPolicyRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> checker.TroubleshootIamPolicyResponse:
Expand All @@ -169,7 +171,7 @@ async def troubleshoot_iam_policy(
does not have that permission.
Args:
request (:class:`google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyRequest`):
request (Union[google.cloud.policytroubleshooter_v1.types.TroubleshootIamPolicyRequest, dict]):
The request object. Request for
[TroubleshootIamPolicy][google.cloud.policytroubleshooter.v1.IamChecker.TroubleshootIamPolicy].
retry (google.api_core.retry.Retry): Designation of what errors, if any,
Expand Down
Expand Up @@ -30,6 +30,8 @@
from google.auth.exceptions import MutualTLSChannelError # type: ignore
from google.oauth2 import service_account # type: ignore

OptionalRetry = Union[retries.Retry, object]

from google.cloud.policytroubleshooter_v1.types import checker
from google.cloud.policytroubleshooter_v1.types import explanations
from .transports.base import IamCheckerTransport, DEFAULT_CLIENT_INFO
Expand Down Expand Up @@ -336,7 +338,7 @@ def troubleshoot_iam_policy(
self,
request: Union[checker.TroubleshootIamPolicyRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> checker.TroubleshootIamPolicyResponse:
Expand Down
Expand Up @@ -15,7 +15,6 @@
#
import abc
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
import packaging.version
import pkg_resources

import google.auth # type: ignore
Expand All @@ -37,15 +36,6 @@
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()

try:
# google.auth.__version__ was added in 1.26.0
_GOOGLE_AUTH_VERSION = google.auth.__version__
except AttributeError:
try: # try pkg_resources if it is available
_GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version
except pkg_resources.DistributionNotFound: # pragma: NO COVER
_GOOGLE_AUTH_VERSION = None


class IamCheckerTransport(abc.ABC):
"""Abstract transport class for IamChecker."""
Expand Down Expand Up @@ -95,7 +85,7 @@ def __init__(
host += ":443"
self._host = host

scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}

# Save the scopes.
self._scopes = scopes
Expand Down Expand Up @@ -128,29 +118,6 @@ def __init__(
# Save the credentials.
self._credentials = credentials

# 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-auth is increased.

# TODO: Remove this function once google-auth >= 1.25.0 is required
@classmethod
def _get_scopes_kwargs(
cls, host: str, scopes: Optional[Sequence[str]]
) -> Dict[str, Optional[Sequence[str]]]:
"""Returns scopes kwargs to pass to google-auth methods depending on the google-auth version"""

scopes_kwargs = {}

if _GOOGLE_AUTH_VERSION and (
packaging.version.parse(_GOOGLE_AUTH_VERSION)
>= packaging.version.parse("1.25.0")
):
scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES}
else:
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES}

return scopes_kwargs

def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
Expand Down
Expand Up @@ -20,7 +20,6 @@
from google.api_core import grpc_helpers_async # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
import packaging.version

import grpc # type: ignore
from grpc.experimental import aio # type: ignore
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -28,11 +28,10 @@
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
# Until this issue is closed
# https://github.com/googleapis/google-cloud-python/issues/10566
"google-api-core[grpc] >= 1.26.0, <3.0.0dev",
"google-api-core[grpc] >= 1.28.0, <3.0.0dev",
"libcst >= 0.2.5",
"proto-plus >= 1.15.0",
"grpc-google-iam-v1",
"packaging >= 14.3",
]

package_root = os.path.abspath(os.path.dirname(__file__))
Expand Down
4 changes: 1 addition & 3 deletions testing/constraints-3.6.txt
Expand Up @@ -19,9 +19,7 @@
#
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
# Then this file should have foo==1.14.0
google-api-core==1.26.0
google-api-core==1.28.0
grpc-google-iam-v1==0.12.3
libcst==0.2.5
proto-plus==1.15.0
packaging==14.3
google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-api-core
88 changes: 9 additions & 79 deletions tests/unit/gapic/policytroubleshooter_v1/test_iam_checker.py
Expand Up @@ -15,7 +15,6 @@
#
import os
import mock
import packaging.version

import grpc
from grpc.experimental import aio
Expand All @@ -37,29 +36,12 @@
)
from google.cloud.policytroubleshooter_v1.services.iam_checker import IamCheckerClient
from google.cloud.policytroubleshooter_v1.services.iam_checker import transports
from google.cloud.policytroubleshooter_v1.services.iam_checker.transports.base import (
_GOOGLE_AUTH_VERSION,
)
from google.cloud.policytroubleshooter_v1.types import checker
from google.cloud.policytroubleshooter_v1.types import explanations
from google.oauth2 import service_account
import google.auth


# 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"),
reason="This test requires google-auth < 1.25.0",
)
requires_google_auth_gte_1_25_0 = pytest.mark.skipif(
packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"),
reason="This test requires google-auth >= 1.25.0",
)


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

Expand Down Expand Up @@ -207,7 +189,7 @@ def test_iam_checker_client_client_options(
options = client_options.ClientOptions(api_endpoint="squid.clam.whelk")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -224,7 +206,7 @@ def test_iam_checker_client_client_options(
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -241,7 +223,7 @@ def test_iam_checker_client_client_options(
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -270,7 +252,7 @@ def test_iam_checker_client_client_options(
options = client_options.ClientOptions(quota_project_id="octopus")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -327,7 +309,7 @@ def test_iam_checker_client_mtls_env_auto(
)
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)

if use_client_cert_env == "false":
expected_client_cert_source = None
Expand Down Expand Up @@ -369,7 +351,7 @@ def test_iam_checker_client_mtls_env_auto(
expected_client_cert_source = client_cert_source_callback

patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand All @@ -391,7 +373,7 @@ def test_iam_checker_client_mtls_env_auto(
return_value=False,
):
patched.return_value = None
client = client_class()
client = client_class(transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -422,7 +404,7 @@ def test_iam_checker_client_client_options_scopes(
options = client_options.ClientOptions(scopes=["1", "2"],)
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file=None,
Expand Down Expand Up @@ -453,7 +435,7 @@ def test_iam_checker_client_client_options_credentials_file(
options = client_options.ClientOptions(credentials_file="credentials.json")
with mock.patch.object(transport_class, "__init__") as patched:
patched.return_value = None
client = client_class(client_options=options)
client = client_class(transport=transport_name, client_options=options)
patched.assert_called_once_with(
credentials=None,
credentials_file="credentials.json",
Expand Down Expand Up @@ -677,7 +659,6 @@ def test_iam_checker_base_transport():
transport.close()


@requires_google_auth_gte_1_25_0
def test_iam_checker_base_transport_with_credentials_file():
# Instantiate the base transport with a credentials file
with mock.patch.object(
Expand All @@ -698,26 +679,6 @@ def test_iam_checker_base_transport_with_credentials_file():
)


@requires_google_auth_lt_1_25_0
def test_iam_checker_base_transport_with_credentials_file_old_google_auth():
# Instantiate the base transport with a credentials file
with mock.patch.object(
google.auth, "load_credentials_from_file", autospec=True
) as load_creds, mock.patch(
"google.cloud.policytroubleshooter_v1.services.iam_checker.transports.IamCheckerTransport._prep_wrapped_messages"
) as Transport:
Transport.return_value = None
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
transport = transports.IamCheckerTransport(
credentials_file="credentials.json", quota_project_id="octopus",
)
load_creds.assert_called_once_with(
"credentials.json",
scopes=("https://www.googleapis.com/auth/cloud-platform",),
quota_project_id="octopus",
)


def test_iam_checker_base_transport_with_adc():
# Test the default credentials are used if credentials and credentials_file are None.
with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch(
Expand All @@ -729,7 +690,6 @@ def test_iam_checker_base_transport_with_adc():
adc.assert_called_once()


@requires_google_auth_gte_1_25_0
def test_iam_checker_auth_adc():
# If no credentials are provided, we should use ADC credentials.
with mock.patch.object(google.auth, "default", autospec=True) as adc:
Expand All @@ -742,23 +702,10 @@ def test_iam_checker_auth_adc():
)


@requires_google_auth_lt_1_25_0
def test_iam_checker_auth_adc_old_google_auth():
# If no credentials are provided, we should use ADC credentials.
with mock.patch.object(google.auth, "default", autospec=True) as adc:
adc.return_value = (ga_credentials.AnonymousCredentials(), None)
IamCheckerClient()
adc.assert_called_once_with(
scopes=("https://www.googleapis.com/auth/cloud-platform",),
quota_project_id=None,
)


@pytest.mark.parametrize(
"transport_class",
[transports.IamCheckerGrpcTransport, transports.IamCheckerGrpcAsyncIOTransport,],
)
@requires_google_auth_gte_1_25_0
def test_iam_checker_transport_auth_adc(transport_class):
# If credentials and host are not provided, the transport class should use
# ADC credentials.
Expand All @@ -772,23 +719,6 @@ def test_iam_checker_transport_auth_adc(transport_class):
)


@pytest.mark.parametrize(
"transport_class",
[transports.IamCheckerGrpcTransport, transports.IamCheckerGrpcAsyncIOTransport,],
)
@requires_google_auth_lt_1_25_0
def test_iam_checker_transport_auth_adc_old_google_auth(transport_class):
# 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:
adc.return_value = (ga_credentials.AnonymousCredentials(), None)
transport_class(quota_project_id="octopus")
adc.assert_called_once_with(
scopes=("https://www.googleapis.com/auth/cloud-platform",),
quota_project_id="octopus",
)


@pytest.mark.parametrize(
"transport_class,grpc_helpers",
[
Expand Down

0 comments on commit 8df5c2c

Please sign in to comment.