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

Commit

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

fix: resolve DuplicateCredentialArgs error when using credentials_file

committer: parthea
PiperOrigin-RevId: 425964861

Source-Link: googleapis/googleapis@84b1a5a

Source-Link: googleapis/googleapis-gen@4fb761b
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGZiNzYxYmJkODUwNmFjMTU2ZjQ5YmFjNWYxODMwNmFhOGViM2FhOCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Feb 3, 2022
1 parent 8145ace commit 4e6e3fc
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class IAMCredentialsAsyncClient:
Service account credentials are used to temporarily assume the
identity of the service account. Supported credential types
include OAuth 2.0 access tokens, OpenID Connect ID tokens, self-
signed JSON Web Tokens (JWTs), and more.
include OAuth 2.0 access tokens, OpenID Connect ID tokens,
self-signed JSON Web Tokens (JWTs), and more.
"""

_client: IAMCredentialsClient
Expand Down Expand Up @@ -295,7 +295,7 @@ async def generate_access_token(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, scope, lifetime])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -421,7 +421,7 @@ async def generate_id_token(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, audience, include_email])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -535,7 +535,7 @@ async def sign_blob(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, payload])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -650,7 +650,7 @@ async def sign_jwt(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, payload])
if request is not None and has_flattened_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class IAMCredentialsClient(metaclass=IAMCredentialsClientMeta):
Service account credentials are used to temporarily assume the
identity of the service account. Supported credential types
include OAuth 2.0 access tokens, OpenID Connect ID tokens, self-
signed JSON Web Tokens (JWTs), and more.
include OAuth 2.0 access tokens, OpenID Connect ID tokens,
self-signed JSON Web Tokens (JWTs), and more.
"""

@staticmethod
Expand Down Expand Up @@ -490,7 +490,7 @@ def generate_access_token(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, scope, lifetime])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -606,7 +606,7 @@ def generate_id_token(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, audience, include_email])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -710,7 +710,7 @@ def sign_blob(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, payload])
if request is not None and has_flattened_params:
Expand Down Expand Up @@ -815,7 +815,7 @@ def sign_jwt(
"""
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name, delegates, payload])
if request is not None and has_flattened_params:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class IAMCredentialsGrpcTransport(IAMCredentialsTransport):
Service account credentials are used to temporarily assume the
identity of the service account. Supported credential types
include OAuth 2.0 access tokens, OpenID Connect ID tokens, self-
signed JSON Web Tokens (JWTs), and more.
include OAuth 2.0 access tokens, OpenID Connect ID tokens,
self-signed JSON Web Tokens (JWTs), and more.
This class defines the same methods as the primary client, so the
primary client can load the underlying transport implementation
Expand Down Expand Up @@ -167,8 +167,11 @@ def __init__(
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
self._host,
# use the credentials which are saved
credentials=self._credentials,
credentials_file=credentials_file,
# Set ``credentials_file`` to ``None`` here as
# the credentials that we saved earlier should be used.
credentials_file=None,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
quota_project_id=quota_project_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class IAMCredentialsGrpcAsyncIOTransport(IAMCredentialsTransport):
Service account credentials are used to temporarily assume the
identity of the service account. Supported credential types
include OAuth 2.0 access tokens, OpenID Connect ID tokens, self-
signed JSON Web Tokens (JWTs), and more.
include OAuth 2.0 access tokens, OpenID Connect ID tokens,
self-signed JSON Web Tokens (JWTs), and more.
This class defines the same methods as the primary client, so the
primary client can load the underlying transport implementation
Expand Down Expand Up @@ -212,8 +212,11 @@ def __init__(
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
self._host,
# use the credentials which are saved
credentials=self._credentials,
credentials_file=credentials_file,
# Set ``credentials_file`` to ``None`` here as
# the credentials that we saved earlier should be used.
credentials_file=None,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
quota_project_id=quota_project_id,
Expand Down
79 changes: 76 additions & 3 deletions tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,28 @@ def test_iam_credentials_client_client_options_scopes(


@pytest.mark.parametrize(
"client_class,transport_class,transport_name",
"client_class,transport_class,transport_name,grpc_helpers",
[
(IAMCredentialsClient, transports.IAMCredentialsGrpcTransport, "grpc"),
(
IAMCredentialsClient,
transports.IAMCredentialsGrpcTransport,
"grpc",
grpc_helpers,
),
(
IAMCredentialsAsyncClient,
transports.IAMCredentialsGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_iam_credentials_client_client_options_credentials_file(
client_class, transport_class, transport_name
client_class, transport_class, transport_name, grpc_helpers
):
# Check the case credentials file is provided.
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, transport=transport_name)
Expand Down Expand Up @@ -563,6 +570,72 @@ def test_iam_credentials_client_client_options_from_dict():
)


@pytest.mark.parametrize(
"client_class,transport_class,transport_name,grpc_helpers",
[
(
IAMCredentialsClient,
transports.IAMCredentialsGrpcTransport,
"grpc",
grpc_helpers,
),
(
IAMCredentialsAsyncClient,
transports.IAMCredentialsGrpcAsyncIOTransport,
"grpc_asyncio",
grpc_helpers_async,
),
],
)
def test_iam_credentials_client_create_channel_credentials_file(
client_class, transport_class, transport_name, grpc_helpers
):
# Check the case credentials file is provided.
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, transport=transport_name)
patched.assert_called_once_with(
credentials=None,
credentials_file="credentials.json",
host=client.DEFAULT_ENDPOINT,
scopes=None,
client_cert_source_for_mtls=None,
quota_project_id=None,
client_info=transports.base.DEFAULT_CLIENT_INFO,
always_use_jwt_access=True,
)

# test that the credentials from file are saved and used as the credentials.
with mock.patch.object(
google.auth, "load_credentials_from_file", autospec=True
) as load_creds, mock.patch.object(
google.auth, "default", autospec=True
) as adc, mock.patch.object(
grpc_helpers, "create_channel"
) as create_channel:
creds = ga_credentials.AnonymousCredentials()
file_creds = ga_credentials.AnonymousCredentials()
load_creds.return_value = (file_creds, None)
adc.return_value = (creds, None)
client = client_class(client_options=options, transport=transport_name)
create_channel.assert_called_with(
"iamcredentials.googleapis.com:443",
credentials=file_creds,
credentials_file=None,
quota_project_id=None,
default_scopes=("https://www.googleapis.com/auth/cloud-platform",),
scopes=None,
default_host="iamcredentials.googleapis.com",
ssl_credentials=None,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)


@pytest.mark.parametrize("request_type", [common.GenerateAccessTokenRequest, dict,])
def test_generate_access_token(request_type, transport: str = "grpc"):
client = IAMCredentialsClient(
Expand Down

0 comments on commit 4e6e3fc

Please sign in to comment.