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

Commit 06928c8

Browse files
fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#301)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 459095142 Source-Link: googleapis/googleapis@4f1be99 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ae686d9cde4fc3e36d0ac02efb8643b15890c1ed Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWU2ODZkOWNkZTRmYzNlMzZkMGFjMDJlZmI4NjQzYjE1ODkwYzFlZCJ9 feat: add audience parameter PiperOrigin-RevId: 456827138 Source-Link: googleapis/googleapis@23f1a15 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4075a8514f676691ec156688a5bbf183aa9893ce Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDA3NWE4NTE0ZjY3NjY5MWVjMTU2Njg4YTViYmYxODNhYTk4OTNjZSJ9
1 parent 2a92896 commit 06928c8

File tree

13 files changed

+141
-23
lines changed

13 files changed

+141
-23
lines changed

.kokoro/samples/python3.6/common.cfg

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Build logs will be here
4+
action {
5+
define_artifacts {
6+
regex: "**/*sponge_log.xml"
7+
}
8+
}
9+
10+
# Specify which tests to run
11+
env_vars: {
12+
key: "RUN_TESTS_SESSION"
13+
value: "py-3.6"
14+
}
15+
16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py36"
20+
}
21+
22+
env_vars: {
23+
key: "TRAMPOLINE_BUILD_FILE"
24+
value: "github/python-containeranalysis/.kokoro/test-samples.sh"
25+
}
26+
27+
# Configure the docker image for kokoro-trampoline.
28+
env_vars: {
29+
key: "TRAMPOLINE_IMAGE"
30+
value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31+
}
32+
33+
# Download secrets for samples
34+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35+
36+
# Download trampoline resources.
37+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38+
39+
# Use the trampoline script to run in docker.
40+
build_file: "python-containeranalysis/.kokoro/trampoline_v2.sh"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}
7+
8+
env_vars: {
9+
key: "TRAMPOLINE_BUILD_FILE"
10+
value: "github/python-containeranalysis/.kokoro/test-samples-against-head.sh"
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "False"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
env_vars: {
4+
key: "INSTALL_LIBRARY_FROM_SOURCE"
5+
value: "True"
6+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def __init__(
422422
quota_project_id=client_options.quota_project_id,
423423
client_info=client_info,
424424
always_use_jwt_access=True,
425+
api_audience=client_options.api_audience,
425426
)
426427

427428
def get_grafeas_client(self) -> grafeas_v1.GrafeasClient:

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
quota_project_id: Optional[str] = None,
5757
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
5858
always_use_jwt_access: Optional[bool] = False,
59+
api_audience: Optional[str] = None,
5960
**kwargs,
6061
) -> None:
6162
"""Instantiate the transport.
@@ -83,11 +84,6 @@ def __init__(
8384
be used for service account credentials.
8485
"""
8586

86-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
87-
if ":" not in host:
88-
host += ":443"
89-
self._host = host
90-
9187
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9288

9389
# Save the scopes.
@@ -108,6 +104,11 @@ def __init__(
108104
credentials, _ = google.auth.default(
109105
**scopes_kwargs, quota_project_id=quota_project_id
110106
)
107+
# Don't apply audience if the credentials file passed from user.
108+
if hasattr(credentials, "with_gdch_audience"):
109+
credentials = credentials.with_gdch_audience(
110+
api_audience if api_audience else host
111+
)
111112

112113
# If the credentials are service account credentials, then always try to use self signed JWT.
113114
if (
@@ -120,6 +121,11 @@ def __init__(
120121
# Save the credentials.
121122
self._credentials = credentials
122123

124+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
125+
if ":" not in host:
126+
host += ":443"
127+
self._host = host
128+
123129
def _prep_wrapped_messages(self, client_info):
124130
# Precompute the wrapped methods.
125131
self._wrapped_methods = {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(
7474
quota_project_id: Optional[str] = None,
7575
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7676
always_use_jwt_access: Optional[bool] = False,
77+
api_audience: Optional[str] = None,
7778
) -> None:
7879
"""Instantiate the transport.
7980
@@ -169,6 +170,7 @@ def __init__(
169170
quota_project_id=quota_project_id,
170171
client_info=client_info,
171172
always_use_jwt_access=always_use_jwt_access,
173+
api_audience=api_audience,
172174
)
173175

174176
if not self._grpc_channel:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(
119119
quota_project_id=None,
120120
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
121121
always_use_jwt_access: Optional[bool] = False,
122+
api_audience: Optional[str] = None,
122123
) -> None:
123124
"""Instantiate the transport.
124125
@@ -214,6 +215,7 @@ def __init__(
214215
quota_project_id=quota_project_id,
215216
client_info=client_info,
216217
always_use_jwt_access=always_use_jwt_access,
218+
api_audience=api_audience,
217219
)
218220

219221
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
version = "2.8.1"
2626
release_status = "Development Status :: 5 - Production/Stable"
2727
dependencies = [
28-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
29-
# Until this issue is closed
30-
# https://github.com/googleapis/google-cloud-python/issues/10566
31-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
28+
"google-api-core[grpc] >= 1.32.0, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*",
3229
"grpc-google-iam-v1 >= 0.12.4, <1.0.0dev",
3330
"proto-plus >= 1.15.0, <2.0.0dev",
3431
"protobuf >= 3.19.0, <4.0.0dev",

testing/constraints-3.6.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

testing/constraints-3.7.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#
66
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
77
# Then this file should have foo==1.14.0
8-
google-api-core==1.31.5
8+
google-api-core==1.32.0
99
grpc-google-iam-v1==0.12.4
1010
proto-plus==1.15.0
1111
libcst==0.2.5
1212
grafeas==1.4.1
1313
protobuf==3.19.0
14+

tests/unit/gapic/containeranalysis_v1/test_container_analysis.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def test_container_analysis_client_client_options(
239239
quota_project_id=None,
240240
client_info=transports.base.DEFAULT_CLIENT_INFO,
241241
always_use_jwt_access=True,
242+
api_audience=None,
242243
)
243244

244245
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -256,6 +257,7 @@ def test_container_analysis_client_client_options(
256257
quota_project_id=None,
257258
client_info=transports.base.DEFAULT_CLIENT_INFO,
258259
always_use_jwt_access=True,
260+
api_audience=None,
259261
)
260262

261263
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
@@ -273,6 +275,7 @@ def test_container_analysis_client_client_options(
273275
quota_project_id=None,
274276
client_info=transports.base.DEFAULT_CLIENT_INFO,
275277
always_use_jwt_access=True,
278+
api_audience=None,
276279
)
277280

278281
# Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
@@ -302,6 +305,25 @@ def test_container_analysis_client_client_options(
302305
quota_project_id="octopus",
303306
client_info=transports.base.DEFAULT_CLIENT_INFO,
304307
always_use_jwt_access=True,
308+
api_audience=None,
309+
)
310+
# Check the case api_endpoint is provided
311+
options = client_options.ClientOptions(
312+
api_audience="https://language.googleapis.com"
313+
)
314+
with mock.patch.object(transport_class, "__init__") as patched:
315+
patched.return_value = None
316+
client = client_class(client_options=options, transport=transport_name)
317+
patched.assert_called_once_with(
318+
credentials=None,
319+
credentials_file=None,
320+
host=client.DEFAULT_ENDPOINT,
321+
scopes=None,
322+
client_cert_source_for_mtls=None,
323+
quota_project_id=None,
324+
client_info=transports.base.DEFAULT_CLIENT_INFO,
325+
always_use_jwt_access=True,
326+
api_audience="https://language.googleapis.com",
305327
)
306328

307329

@@ -379,6 +401,7 @@ def test_container_analysis_client_mtls_env_auto(
379401
quota_project_id=None,
380402
client_info=transports.base.DEFAULT_CLIENT_INFO,
381403
always_use_jwt_access=True,
404+
api_audience=None,
382405
)
383406

384407
# Check the case ADC client cert is provided. Whether client cert is used depends on
@@ -413,6 +436,7 @@ def test_container_analysis_client_mtls_env_auto(
413436
quota_project_id=None,
414437
client_info=transports.base.DEFAULT_CLIENT_INFO,
415438
always_use_jwt_access=True,
439+
api_audience=None,
416440
)
417441

418442
# Check the case client_cert_source and ADC client cert are not provided.
@@ -435,6 +459,7 @@ def test_container_analysis_client_mtls_env_auto(
435459
quota_project_id=None,
436460
client_info=transports.base.DEFAULT_CLIENT_INFO,
437461
always_use_jwt_access=True,
462+
api_audience=None,
438463
)
439464

440465

@@ -549,6 +574,7 @@ def test_container_analysis_client_client_options_scopes(
549574
quota_project_id=None,
550575
client_info=transports.base.DEFAULT_CLIENT_INFO,
551576
always_use_jwt_access=True,
577+
api_audience=None,
552578
)
553579

554580

@@ -587,6 +613,7 @@ def test_container_analysis_client_client_options_credentials_file(
587613
quota_project_id=None,
588614
client_info=transports.base.DEFAULT_CLIENT_INFO,
589615
always_use_jwt_access=True,
616+
api_audience=None,
590617
)
591618

592619

@@ -607,6 +634,7 @@ def test_container_analysis_client_client_options_from_dict():
607634
quota_project_id=None,
608635
client_info=transports.base.DEFAULT_CLIENT_INFO,
609636
always_use_jwt_access=True,
637+
api_audience=None,
610638
)
611639

612640

@@ -645,6 +673,7 @@ def test_container_analysis_client_create_channel_credentials_file(
645673
quota_project_id=None,
646674
client_info=transports.base.DEFAULT_CLIENT_INFO,
647675
always_use_jwt_access=True,
676+
api_audience=None,
648677
)
649678

650679
# test that the credentials from file are saved and used as the credentials.
@@ -1927,6 +1956,28 @@ def test_container_analysis_transport_auth_adc(transport_class):
19271956
)
19281957

19291958

1959+
@pytest.mark.parametrize(
1960+
"transport_class",
1961+
[
1962+
transports.ContainerAnalysisGrpcTransport,
1963+
transports.ContainerAnalysisGrpcAsyncIOTransport,
1964+
],
1965+
)
1966+
def test_container_analysis_transport_auth_gdch_credentials(transport_class):
1967+
host = "https://language.com"
1968+
api_audience_tests = [None, "https://language2.com"]
1969+
api_audience_expect = [host, "https://language2.com"]
1970+
for t, e in zip(api_audience_tests, api_audience_expect):
1971+
with mock.patch.object(google.auth, "default", autospec=True) as adc:
1972+
gdch_mock = mock.MagicMock()
1973+
type(gdch_mock).with_gdch_audience = mock.PropertyMock(
1974+
return_value=gdch_mock
1975+
)
1976+
adc.return_value = (gdch_mock, None)
1977+
transport_class(host=host, api_audience=t)
1978+
gdch_mock.with_gdch_audience.assert_called_once_with(e)
1979+
1980+
19301981
@pytest.mark.parametrize(
19311982
"transport_class,grpc_helpers",
19321983
[
@@ -2372,4 +2423,5 @@ def test_api_key_credentials(client_class, transport_class):
23722423
quota_project_id=None,
23732424
client_info=transports.base.DEFAULT_CLIENT_INFO,
23742425
always_use_jwt_access=True,
2426+
api_audience=None,
23752427
)

0 commit comments

Comments
 (0)