Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 1d8fe5f

Browse files
authored
feat: add audience parameter (#455)
fix(deps): require google-api-core>=1.32.0,>=2.8.0
1 parent 401bd73 commit 1d8fe5f

File tree

13 files changed

+152
-27
lines changed

13 files changed

+152
-27
lines changed

google/cloud/vision_v1/services/image_annotator/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def __init__(
453453
quota_project_id=client_options.quota_project_id,
454454
client_info=client_info,
455455
always_use_jwt_access=True,
456+
api_audience=client_options.api_audience,
456457
)
457458

458459
def batch_annotate_images(

google/cloud/vision_v1/services/image_annotator/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6161
always_use_jwt_access: Optional[bool] = False,
62+
api_audience: Optional[str] = None,
6263
**kwargs,
6364
) -> None:
6465
"""Instantiate the transport.
@@ -86,11 +87,6 @@ def __init__(
8687
be used for service account credentials.
8788
"""
8889

89-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
90-
if ":" not in host:
91-
host += ":443"
92-
self._host = host
93-
9490
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9591

9692
# Save the scopes.
@@ -111,6 +107,11 @@ def __init__(
111107
credentials, _ = google.auth.default(
112108
**scopes_kwargs, quota_project_id=quota_project_id
113109
)
110+
# Don't apply audience if the credentials file passed from user.
111+
if hasattr(credentials, "with_gdch_audience"):
112+
credentials = credentials.with_gdch_audience(
113+
api_audience if api_audience else host
114+
)
114115

115116
# If the credentials are service account credentials, then always try to use self signed JWT.
116117
if (
@@ -123,6 +124,11 @@ def __init__(
123124
# Save the credentials.
124125
self._credentials = credentials
125126

127+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
128+
if ":" not in host:
129+
host += ":443"
130+
self._host = host
131+
126132
def _prep_wrapped_messages(self, client_info):
127133
# Precompute the wrapped methods.
128134
self._wrapped_methods = {

google/cloud/vision_v1/services/image_annotator/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
quota_project_id: Optional[str] = None,
6464
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6565
always_use_jwt_access: Optional[bool] = False,
66+
api_audience: Optional[str] = None,
6667
) -> None:
6768
"""Instantiate the transport.
6869
@@ -159,6 +160,7 @@ def __init__(
159160
quota_project_id=quota_project_id,
160161
client_info=client_info,
161162
always_use_jwt_access=always_use_jwt_access,
163+
api_audience=api_audience,
162164
)
163165

164166
if not self._grpc_channel:

google/cloud/vision_v1/services/image_annotator/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
quota_project_id=None,
109109
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
110110
always_use_jwt_access: Optional[bool] = False,
111+
api_audience: Optional[str] = None,
111112
) -> None:
112113
"""Instantiate the transport.
113114
@@ -204,6 +205,7 @@ def __init__(
204205
quota_project_id=quota_project_id,
205206
client_info=client_info,
206207
always_use_jwt_access=always_use_jwt_access,
208+
api_audience=api_audience,
207209
)
208210

209211
if not self._grpc_channel:

google/cloud/vision_v1/services/product_search/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ def __init__(
495495
quota_project_id=client_options.quota_project_id,
496496
client_info=client_info,
497497
always_use_jwt_access=True,
498+
api_audience=client_options.api_audience,
498499
)
499500

500501
def create_product_set(

google/cloud/vision_v1/services/product_search/transports/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
quota_project_id: Optional[str] = None,
6161
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6262
always_use_jwt_access: Optional[bool] = False,
63+
api_audience: Optional[str] = None,
6364
**kwargs,
6465
) -> None:
6566
"""Instantiate the transport.
@@ -87,11 +88,6 @@ def __init__(
8788
be used for service account credentials.
8889
"""
8990

90-
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
91-
if ":" not in host:
92-
host += ":443"
93-
self._host = host
94-
9591
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
9692

9793
# Save the scopes.
@@ -112,6 +108,11 @@ def __init__(
112108
credentials, _ = google.auth.default(
113109
**scopes_kwargs, quota_project_id=quota_project_id
114110
)
111+
# Don't apply audience if the credentials file passed from user.
112+
if hasattr(credentials, "with_gdch_audience"):
113+
credentials = credentials.with_gdch_audience(
114+
api_audience if api_audience else host
115+
)
115116

116117
# If the credentials are service account credentials, then always try to use self signed JWT.
117118
if (
@@ -124,6 +125,11 @@ def __init__(
124125
# Save the credentials.
125126
self._credentials = credentials
126127

128+
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
129+
if ":" not in host:
130+
host += ":443"
131+
self._host = host
132+
127133
def _prep_wrapped_messages(self, client_info):
128134
# Precompute the wrapped methods.
129135
self._wrapped_methods = {

google/cloud/vision_v1/services/product_search/transports/grpc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __init__(
7878
quota_project_id: Optional[str] = None,
7979
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
8080
always_use_jwt_access: Optional[bool] = False,
81+
api_audience: Optional[str] = None,
8182
) -> None:
8283
"""Instantiate the transport.
8384
@@ -174,6 +175,7 @@ def __init__(
174175
quota_project_id=quota_project_id,
175176
client_info=client_info,
176177
always_use_jwt_access=always_use_jwt_access,
178+
api_audience=api_audience,
177179
)
178180

179181
if not self._grpc_channel:

google/cloud/vision_v1/services/product_search/transports/grpc_asyncio.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(
123123
quota_project_id=None,
124124
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
125125
always_use_jwt_access: Optional[bool] = False,
126+
api_audience: Optional[str] = None,
126127
) -> None:
127128
"""Instantiate the transport.
128129
@@ -219,6 +220,7 @@ def __init__(
219220
quota_project_id=quota_project_id,
220221
client_info=client_info,
221222
always_use_jwt_access=always_use_jwt_access,
223+
api_audience=api_audience,
222224
)
223225

224226
if not self._grpc_channel:

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
version = "2.7.3"
2323
release_status = "Development Status :: 5 - Production/Stable"
2424
dependencies = [
25-
# NOTE: Maintainers, please do not require google-api-core>=2.x.x
26-
# Until this issue is closed
27-
# https://github.com/googleapis/google-cloud-python/issues/10566
28-
"google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0",
25+
"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.*",
2926
"proto-plus >= 1.15.0, <2.0.0dev",
3027
"protobuf >= 3.19.0, <4.0.0dev",
3128
]

testing/constraints-3.6.txt

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

0 commit comments

Comments
 (0)