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

Commit 237c204

Browse files
authored
fix: allow credentials to propagate when using get_grafeas_client() (#251)
1 parent a9b850b commit 237c204

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,14 @@ def __init__(
221221
)
222222

223223
def get_grafeas_client(self) -> grafeas_v1.GrafeasClient:
224-
transport = type(self).get_transport_class("grpc_asyncio")()
225224
grafeas_transport = grafeas_v1.services.grafeas.transports.GrafeasGrpcTransport(
226-
host=transport._host, scopes=transport.AUTH_SCOPES
225+
credentials=self.transport._credentials,
226+
# Set ``credentials_file`` to ``None`` here as
227+
# transport._credentials contains the credentials
228+
# which are saved
229+
credentials_file=None,
230+
host=self.transport._host,
231+
scopes=self.transport.AUTH_SCOPES,
227232
)
228233
return grafeas_v1.GrafeasClient(transport=grafeas_transport)
229234

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,14 @@ def __init__(
406406
)
407407

408408
def get_grafeas_client(self) -> grafeas_v1.GrafeasClient:
409-
transport = type(self).get_transport_class("grpc")()
410409
grafeas_transport = grafeas_v1.services.grafeas.transports.GrafeasGrpcTransport(
411-
host=transport._host, scopes=transport.AUTH_SCOPES
410+
credentials=self.transport._credentials,
411+
# Set ``credentials_file`` to ``None`` here as
412+
# transport._credentials contains the credentials
413+
# which are saved
414+
credentials_file=None,
415+
host=self.transport._host,
416+
scopes=self.transport.AUTH_SCOPES,
412417
)
413418
return grafeas_v1.GrafeasClient(transport=grafeas_transport)
414419

owlbot.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@
6969
r'''\n\g<1>def get_grafeas_client(
7070
self
7171
) -> grafeas_v1.GrafeasClient:
72-
transport = type(self).get_transport_class("grpc")()
7372
grafeas_transport = grafeas_v1.services.grafeas.transports.GrafeasGrpcTransport(
74-
host=transport._host,
75-
scopes=transport.AUTH_SCOPES
73+
credentials=self.transport._credentials,
74+
# Set ``credentials_file`` to ``None`` here as
75+
# transport._credentials contains the credentials
76+
# which are saved
77+
credentials_file=None,
78+
host = self.transport._host,
79+
scopes=self.transport.AUTH_SCOPES
7680
)
7781
return grafeas_v1.GrafeasClient(transport=grafeas_transport)
7882
@@ -86,17 +90,63 @@
8690
r'''\n\g<1>def get_grafeas_client(
8791
self
8892
) -> grafeas_v1.GrafeasClient:
89-
transport = type(self).get_transport_class("grpc_asyncio")()
9093
grafeas_transport = grafeas_v1.services.grafeas.transports.GrafeasGrpcTransport(
91-
host=transport._host,
92-
scopes=transport.AUTH_SCOPES
94+
credentials=self.transport._credentials,
95+
# Set ``credentials_file`` to ``None`` here as
96+
# transport._credentials contains the credentials
97+
# which are saved
98+
credentials_file=None,
99+
host = self.transport._host,
100+
scopes=self.transport.AUTH_SCOPES
93101
)
94102
return grafeas_v1.GrafeasClient(transport=grafeas_transport)
95103
96104
\g<1># Service calls
97105
\g<1>async def set_iam_policy(''',
98106
)
99107

108+
# Add test to ensure that credentials propagate to client.get_grafeas_client()
109+
num_replacements = s.replace(library / "tests/**/test_container_analysis.py",
110+
"""create_channel.assert_called_with\(
111+
"containeranalysis.googleapis.com:443",
112+
credentials=file_creds,
113+
credentials_file=None,
114+
quota_project_id=None,
115+
default_scopes=\(
116+
'https://www.googleapis.com/auth/cloud-platform',
117+
\),
118+
scopes=None,
119+
default_host="containeranalysis.googleapis.com",
120+
ssl_credentials=None,
121+
options=\[
122+
\("grpc.max_send_message_length", -1\),
123+
\("grpc.max_receive_message_length", -1\),
124+
\],
125+
\)""",
126+
"""create_channel.assert_called_with(
127+
"containeranalysis.googleapis.com:443",
128+
credentials=file_creds,
129+
credentials_file=None,
130+
quota_project_id=None,
131+
default_scopes=(
132+
'https://www.googleapis.com/auth/cloud-platform',
133+
),
134+
scopes=None,
135+
default_host="containeranalysis.googleapis.com",
136+
ssl_credentials=None,
137+
options=[
138+
("grpc.max_send_message_length", -1),
139+
("grpc.max_receive_message_length", -1),
140+
],
141+
)
142+
143+
# Also check client.get_grafeas_client() to make sure that the file credentials are used
144+
assert file_creds == client.get_grafeas_client().transport._credentials
145+
"""
146+
)
147+
148+
assert num_replacements == 1
149+
100150
s.move(library, excludes=["setup.py", "README.rst", "docs/index.rst"])
101151

102152
s.remove_staging_dirs()

tests/unit/gapic/containeranalysis_v1/test_container_analysis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ def test_container_analysis_client_create_channel_credentials_file(
650650
],
651651
)
652652

653+
# Also check client.get_grafeas_client() to make sure that the file credentials are used
654+
assert file_creds == client.get_grafeas_client().transport._credentials
655+
653656

654657
@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,])
655658
def test_set_iam_policy(request_type, transport: str = "grpc"):

0 commit comments

Comments
 (0)