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

Commit b660c07

Browse files
chore: use gapic-generator-python 0.62.1 (#73)
- [ ] 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 1276804 commit b660c07

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

google/cloud/shell_v1/services/cloud_shell_service/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ async def get_environment(
256256
257257
"""
258258
# Create or coerce a protobuf request object.
259-
# Sanity check: If we got a request object, we should *not* have
259+
# Quick check: If we got a request object, we should *not* have
260260
# gotten any keyword arguments that map to the request.
261261
has_flattened_params = any([name])
262262
if request is not None and has_flattened_params:

google/cloud/shell_v1/services/cloud_shell_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def get_environment(
450450
451451
"""
452452
# Create or coerce a protobuf request object.
453-
# Sanity check: If we got a request object, we should *not* have
453+
# Quick check: If we got a request object, we should *not* have
454454
# gotten any keyword arguments that map to the request.
455455
has_flattened_params = any([name])
456456
if request is not None and has_flattened_params:

google/cloud/shell_v1/services/cloud_shell_service/transports/grpc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ def __init__(
168168
if not self._grpc_channel:
169169
self._grpc_channel = type(self).create_channel(
170170
self._host,
171+
# use the credentials which are saved
171172
credentials=self._credentials,
172-
credentials_file=credentials_file,
173+
# Set ``credentials_file`` to ``None`` here as
174+
# the credentials that we saved earlier should be used.
175+
credentials_file=None,
173176
scopes=self._scopes,
174177
ssl_credentials=self._ssl_channel_credentials,
175178
quota_project_id=quota_project_id,
@@ -242,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsClient:
242245
This property caches on the instance; repeated calls return the same
243246
client.
244247
"""
245-
# Sanity check: Only create a new client if we do not already have one.
248+
# Quick check: Only create a new client if we do not already have one.
246249
if self._operations_client is None:
247250
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
248251

google/cloud/shell_v1/services/cloud_shell_service/transports/grpc_asyncio.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,11 @@ def __init__(
213213
if not self._grpc_channel:
214214
self._grpc_channel = type(self).create_channel(
215215
self._host,
216+
# use the credentials which are saved
216217
credentials=self._credentials,
217-
credentials_file=credentials_file,
218+
# Set ``credentials_file`` to ``None`` here as
219+
# the credentials that we saved earlier should be used.
220+
credentials_file=None,
218221
scopes=self._scopes,
219222
ssl_credentials=self._ssl_channel_credentials,
220223
quota_project_id=quota_project_id,
@@ -244,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
244247
This property caches on the instance; repeated calls return the same
245248
client.
246249
"""
247-
# Sanity check: Only create a new client if we do not already have one.
250+
# Quick check: Only create a new client if we do not already have one.
248251
if self._operations_client is None:
249252
self._operations_client = operations_v1.OperationsAsyncClient(
250253
self.grpc_channel

tests/unit/gapic/shell_v1/test_cloud_shell_service.py

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from google.api_core import gapic_v1
3030
from google.api_core import grpc_helpers
3131
from google.api_core import grpc_helpers_async
32+
from google.api_core import operation
3233
from google.api_core import operation_async # type: ignore
3334
from google.api_core import operations_v1
3435
from google.api_core import path_template
@@ -525,21 +526,28 @@ def test_cloud_shell_service_client_client_options_scopes(
525526

526527

527528
@pytest.mark.parametrize(
528-
"client_class,transport_class,transport_name",
529+
"client_class,transport_class,transport_name,grpc_helpers",
529530
[
530-
(CloudShellServiceClient, transports.CloudShellServiceGrpcTransport, "grpc"),
531+
(
532+
CloudShellServiceClient,
533+
transports.CloudShellServiceGrpcTransport,
534+
"grpc",
535+
grpc_helpers,
536+
),
531537
(
532538
CloudShellServiceAsyncClient,
533539
transports.CloudShellServiceGrpcAsyncIOTransport,
534540
"grpc_asyncio",
541+
grpc_helpers_async,
535542
),
536543
],
537544
)
538545
def test_cloud_shell_service_client_client_options_credentials_file(
539-
client_class, transport_class, transport_name
546+
client_class, transport_class, transport_name, grpc_helpers
540547
):
541548
# Check the case credentials file is provided.
542549
options = client_options.ClientOptions(credentials_file="credentials.json")
550+
543551
with mock.patch.object(transport_class, "__init__") as patched:
544552
patched.return_value = None
545553
client = client_class(client_options=options, transport=transport_name)
@@ -575,6 +583,72 @@ def test_cloud_shell_service_client_client_options_from_dict():
575583
)
576584

577585

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

0 commit comments

Comments
 (0)