Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit fecf484

Browse files
chore: use gapic-generator-python 0.62.1 (#240)
- [ ] 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: https://github.com/googleapis/googleapis-gen/commit/4fb761bbd8506ac156f49bac5f18306aa8eb3aa8 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGZiNzYxYmJkODUwNmFjMTU2ZjQ5YmFjNWYxODMwNmFhOGViM2FhOCJ9
1 parent 72c88b3 commit fecf484

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

google/cloud/devtools/containeranalysis_v1/services/container_analysis/async_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async def set_iam_policy(
327327
328328
"""
329329
# Create or coerce a protobuf request object.
330-
# Sanity check: If we got a request object, we should *not* have
330+
# Quick check: If we got a request object, we should *not* have
331331
# gotten any keyword arguments that map to the request.
332332
has_flattened_params = any([resource])
333333
if request is not None and has_flattened_params:
@@ -461,7 +461,7 @@ async def get_iam_policy(
461461
462462
"""
463463
# Create or coerce a protobuf request object.
464-
# Sanity check: If we got a request object, we should *not* have
464+
# Quick check: If we got a request object, we should *not* have
465465
# gotten any keyword arguments that map to the request.
466466
has_flattened_params = any([resource])
467467
if request is not None and has_flattened_params:
@@ -549,7 +549,7 @@ async def test_iam_permissions(
549549
Response message for TestIamPermissions method.
550550
"""
551551
# Create or coerce a protobuf request object.
552-
# Sanity check: If we got a request object, we should *not* have
552+
# Quick check: If we got a request object, we should *not* have
553553
# gotten any keyword arguments that map to the request.
554554
has_flattened_params = any([resource, permissions])
555555
if request is not None and has_flattened_params:
@@ -632,7 +632,7 @@ async def get_vulnerability_occurrences_summary(
632632
633633
"""
634634
# Create or coerce a protobuf request object.
635-
# Sanity check: If we got a request object, we should *not* have
635+
# Quick check: If we got a request object, we should *not* have
636636
# gotten any keyword arguments that map to the request.
637637
has_flattened_params = any([parent, filter])
638638
if request is not None and has_flattened_params:

google/cloud/devtools/containeranalysis_v1/services/container_analysis/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def set_iam_policy(
512512
513513
"""
514514
# Create or coerce a protobuf request object.
515-
# Sanity check: If we got a request object, we should *not* have
515+
# Quick check: If we got a request object, we should *not* have
516516
# gotten any keyword arguments that map to the request.
517517
has_flattened_params = any([resource])
518518
if request is not None and has_flattened_params:
@@ -645,7 +645,7 @@ def get_iam_policy(
645645
646646
"""
647647
# Create or coerce a protobuf request object.
648-
# Sanity check: If we got a request object, we should *not* have
648+
# Quick check: If we got a request object, we should *not* have
649649
# gotten any keyword arguments that map to the request.
650650
has_flattened_params = any([resource])
651651
if request is not None and has_flattened_params:
@@ -732,7 +732,7 @@ def test_iam_permissions(
732732
Response message for TestIamPermissions method.
733733
"""
734734
# Create or coerce a protobuf request object.
735-
# Sanity check: If we got a request object, we should *not* have
735+
# Quick check: If we got a request object, we should *not* have
736736
# gotten any keyword arguments that map to the request.
737737
has_flattened_params = any([resource, permissions])
738738
if request is not None and has_flattened_params:
@@ -814,7 +814,7 @@ def get_vulnerability_occurrences_summary(
814814
815815
"""
816816
# Create or coerce a protobuf request object.
817-
# Sanity check: If we got a request object, we should *not* have
817+
# Quick check: If we got a request object, we should *not* have
818818
# gotten any keyword arguments that map to the request.
819819
has_flattened_params = any([parent, filter])
820820
if request is not None and has_flattened_params:

google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ def __init__(
174174
if not self._grpc_channel:
175175
self._grpc_channel = type(self).create_channel(
176176
self._host,
177+
# use the credentials which are saved
177178
credentials=self._credentials,
178-
credentials_file=credentials_file,
179+
# Set ``credentials_file`` to ``None`` here as
180+
# the credentials that we saved earlier should be used.
181+
credentials_file=None,
179182
scopes=self._scopes,
180183
ssl_credentials=self._ssl_channel_credentials,
181184
quota_project_id=quota_project_id,

google/cloud/devtools/containeranalysis_v1/services/container_analysis/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ def __init__(
219219
if not self._grpc_channel:
220220
self._grpc_channel = type(self).create_channel(
221221
self._host,
222+
# use the credentials which are saved
222223
credentials=self._credentials,
223-
credentials_file=credentials_file,
224+
# Set ``credentials_file`` to ``None`` here as
225+
# the credentials that we saved earlier should be used.
226+
credentials_file=None,
224227
scopes=self._scopes,
225228
ssl_credentials=self._ssl_channel_credentials,
226229
quota_project_id=quota_project_id,

tests/unit/gapic/containeranalysis_v1/test_container_analysis.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,28 @@ def test_container_analysis_client_client_options_scopes(
528528

529529

530530
@pytest.mark.parametrize(
531-
"client_class,transport_class,transport_name",
531+
"client_class,transport_class,transport_name,grpc_helpers",
532532
[
533-
(ContainerAnalysisClient, transports.ContainerAnalysisGrpcTransport, "grpc"),
533+
(
534+
ContainerAnalysisClient,
535+
transports.ContainerAnalysisGrpcTransport,
536+
"grpc",
537+
grpc_helpers,
538+
),
534539
(
535540
ContainerAnalysisAsyncClient,
536541
transports.ContainerAnalysisGrpcAsyncIOTransport,
537542
"grpc_asyncio",
543+
grpc_helpers_async,
538544
),
539545
],
540546
)
541547
def test_container_analysis_client_client_options_credentials_file(
542-
client_class, transport_class, transport_name
548+
client_class, transport_class, transport_name, grpc_helpers
543549
):
544550
# Check the case credentials file is provided.
545551
options = client_options.ClientOptions(credentials_file="credentials.json")
552+
546553
with mock.patch.object(transport_class, "__init__") as patched:
547554
patched.return_value = None
548555
client = client_class(client_options=options, transport=transport_name)
@@ -578,6 +585,72 @@ def test_container_analysis_client_client_options_from_dict():
578585
)
579586

580587

588+
@pytest.mark.parametrize(
589+
"client_class,transport_class,transport_name,grpc_helpers",
590+
[
591+
(
592+
ContainerAnalysisClient,
593+
transports.ContainerAnalysisGrpcTransport,
594+
"grpc",
595+
grpc_helpers,
596+
),
597+
(
598+
ContainerAnalysisAsyncClient,
599+
transports.ContainerAnalysisGrpcAsyncIOTransport,
600+
"grpc_asyncio",
601+
grpc_helpers_async,
602+
),
603+
],
604+
)
605+
def test_container_analysis_client_create_channel_credentials_file(
606+
client_class, transport_class, transport_name, grpc_helpers
607+
):
608+
# Check the case credentials file is provided.
609+
options = client_options.ClientOptions(credentials_file="credentials.json")
610+
611+
with mock.patch.object(transport_class, "__init__") as patched:
612+
patched.return_value = None
613+
client = client_class(client_options=options, transport=transport_name)
614+
patched.assert_called_once_with(
615+
credentials=None,
616+
credentials_file="credentials.json",
617+
host=client.DEFAULT_ENDPOINT,
618+
scopes=None,
619+
client_cert_source_for_mtls=None,
620+
quota_project_id=None,
621+
client_info=transports.base.DEFAULT_CLIENT_INFO,
622+
always_use_jwt_access=True,
623+
)
624+
625+
# test that the credentials from file are saved and used as the credentials.
626+
with mock.patch.object(
627+
google.auth, "load_credentials_from_file", autospec=True
628+
) as load_creds, mock.patch.object(
629+
google.auth, "default", autospec=True
630+
) as adc, mock.patch.object(
631+
grpc_helpers, "create_channel"
632+
) as create_channel:
633+
creds = ga_credentials.AnonymousCredentials()
634+
file_creds = ga_credentials.AnonymousCredentials()
635+
load_creds.return_value = (file_creds, None)
636+
adc.return_value = (creds, None)
637+
client = client_class(client_options=options, transport=transport_name)
638+
create_channel.assert_called_with(
639+
"containeranalysis.googleapis.com:443",
640+
credentials=file_creds,
641+
credentials_file=None,
642+
quota_project_id=None,
643+
default_scopes=("https://www.googleapis.com/auth/cloud-platform",),
644+
scopes=None,
645+
default_host="containeranalysis.googleapis.com",
646+
ssl_credentials=None,
647+
options=[
648+
("grpc.max_send_message_length", -1),
649+
("grpc.max_receive_message_length", -1),
650+
],
651+
)
652+
653+
581654
@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,])
582655
def test_set_iam_policy(request_type, transport: str = "grpc"):
583656
client = ContainerAnalysisClient(

0 commit comments

Comments
 (0)