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

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: disable always_use_jwt_access (#4)
Committer: @busunkim96
PiperOrigin-RevId: 382142900

Source-Link: googleapis/googleapis@513440f

Source-Link: googleapis/googleapis-gen@7b1e2c3
  • Loading branch information
gcf-owl-bot[bot] committed Jul 1, 2021
1 parent a1749da commit cfca4f8
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 33 deletions.
Expand Up @@ -101,7 +101,7 @@ def __init__(
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)

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

# If no credentials are provided, then determine the appropriate
# defaults.
Expand Down
Expand Up @@ -78,6 +78,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -118,6 +119,8 @@ def __init__(
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.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
Expand Down Expand Up @@ -170,7 +173,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -124,6 +124,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -165,6 +166,8 @@ def __init__(
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.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down Expand Up @@ -216,7 +219,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -102,7 +102,7 @@ def __init__(
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)

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

# If no credentials are provided, then determine the appropriate
# defaults.
Expand Down
Expand Up @@ -70,6 +70,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -110,6 +111,8 @@ def __init__(
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.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
Expand Down Expand Up @@ -162,7 +165,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
Expand Up @@ -116,6 +116,7 @@ def __init__(
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
always_use_jwt_access: Optional[bool] = False,
) -> None:
"""Instantiate the transport.
Expand Down Expand Up @@ -157,6 +158,8 @@ def __init__(
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.
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
be used for service account credentials.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
Expand Down Expand Up @@ -208,7 +211,7 @@ def __init__(
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
always_use_jwt_access=always_use_jwt_access,
)

if not self._grpc_channel:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -25,7 +25,7 @@
release_status = "Development Status :: 4 - Beta"
url = "https://github.com/googleapis/python-debugger-client"
dependencies = [
"google-api-core[grpc] >= 1.22.2, < 2.0.0dev",
"google-api-core[grpc] >= 1.26.0, <2.0.0dev",
"proto-plus >= 1.15.0",
"packaging >= 14.3",
"google-cloud-source-context >= 0.1.0, < 1.0.0dev",
Expand Down
35 changes: 22 additions & 13 deletions tests/unit/gapic/debugger_v2/test_controller2.py
Expand Up @@ -123,7 +123,25 @@ def test_controller2_client_service_account_always_use_jwt(client_class):
) as use_jwt:
creds = service_account.Credentials(None, None, None)
client = client_class(credentials=creds)
use_jwt.assert_called_with(True)
use_jwt.assert_not_called()


@pytest.mark.parametrize(
"transport_class,transport_name",
[
(transports.Controller2GrpcTransport, "grpc"),
(transports.Controller2GrpcAsyncIOTransport, "grpc_asyncio"),
],
)
def test_controller2_client_service_account_always_use_jwt_true(
transport_class, transport_name
):
with mock.patch.object(
service_account.Credentials, "with_always_use_jwt_access", create=True
) as use_jwt:
creds = service_account.Credentials(None, None, None)
transport = transport_class(credentials=creds, always_use_jwt_access=True)
use_jwt.assert_called_once_with(True)


@pytest.mark.parametrize("client_class", [Controller2Client, Controller2AsyncClient,])
Expand Down Expand Up @@ -1232,10 +1250,7 @@ def test_controller2_grpc_transport_client_cert_source_for_mtls(transport_class)
"squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_channel_creds,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -1339,10 +1354,7 @@ def test_controller2_transport_channel_mtls_with_client_cert_source(transport_cl
"mtls.squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -1386,10 +1398,7 @@ def test_controller2_transport_channel_mtls_with_adc(transport_class):
"mtls.squid.clam.whelk:443",
credentials=mock_cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down
35 changes: 22 additions & 13 deletions tests/unit/gapic/debugger_v2/test_debugger2.py
Expand Up @@ -120,7 +120,25 @@ def test_debugger2_client_service_account_always_use_jwt(client_class):
) as use_jwt:
creds = service_account.Credentials(None, None, None)
client = client_class(credentials=creds)
use_jwt.assert_called_with(True)
use_jwt.assert_not_called()


@pytest.mark.parametrize(
"transport_class,transport_name",
[
(transports.Debugger2GrpcTransport, "grpc"),
(transports.Debugger2GrpcAsyncIOTransport, "grpc_asyncio"),
],
)
def test_debugger2_client_service_account_always_use_jwt_true(
transport_class, transport_name
):
with mock.patch.object(
service_account.Credentials, "with_always_use_jwt_access", create=True
) as use_jwt:
creds = service_account.Credentials(None, None, None)
transport = transport_class(credentials=creds, always_use_jwt_access=True)
use_jwt.assert_called_once_with(True)


@pytest.mark.parametrize("client_class", [Debugger2Client, Debugger2AsyncClient,])
Expand Down Expand Up @@ -1545,10 +1563,7 @@ def test_debugger2_grpc_transport_client_cert_source_for_mtls(transport_class):
"squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_channel_creds,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -1652,10 +1667,7 @@ def test_debugger2_transport_channel_mtls_with_client_cert_source(transport_clas
"mtls.squid.clam.whelk:443",
credentials=cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down Expand Up @@ -1699,10 +1711,7 @@ def test_debugger2_transport_channel_mtls_with_adc(transport_class):
"mtls.squid.clam.whelk:443",
credentials=mock_cred,
credentials_file=None,
scopes=(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
scopes=None,
ssl_credentials=mock_ssl_cred,
quota_project_id=None,
options=[
Expand Down

0 comments on commit cfca4f8

Please sign in to comment.