GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add always_use_jwt_access (#498) · bleakley/python-aiplatform@6df4866

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google/cloud
    • aiplatform_v1beta1/services
      • dataset_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • endpoint_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • featurestore_online_serving_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • featurestore_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • index_endpoint_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • index_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • job_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • metadata_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • migration_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • model_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • pipeline_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • prediction_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • specialist_pool_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • tensorboard_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • vizier_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
    • aiplatform_v1/services
      • dataset_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • endpoint_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • job_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • migration_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • model_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • pipeline_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • prediction_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
      • specialist_pool_service/transports
        • base.py
        • grpc.py
        • grpc_asyncio.py
  • owlbot.py
  • schema/predict
    • instance
      • noxfile.py
      • setup.py
    • params
      • noxfile.py
      • setup.py
    • prediction
      • noxfile.py
      • setup.py
  • setup.py
  • testing
    • constraints-3.6.txt
  • tests/unit/gapic
    • aiplatform_v1beta1
      • test_dataset_service.py
      • test_endpoint_service.py
      • test_featurestore_online_serving_service.py
      • test_featurestore_service.py
      • test_index_endpoint_service.py
      • test_index_service.py
      • test_job_service.py
      • test_metadata_service.py
      • test_migration_service.py
      • test_model_service.py
      • test_pipeline_service.py
      • test_prediction_service.py
      • test_specialist_pool_service.py
      • test_tensorboard_service.py
      • test_vizier_service.py
    • aiplatform_v1
      • test_dataset_service.py
      • test_endpoint_service.py
      • test_job_service.py
      • test_migration_service.py
      • test_model_service.py
      • test_pipeline_service.py
      • test_prediction_service.py
      • test_specialist_pool_service.py
    • definition_v1beta1
      • __init__.py
    • definition_v1
      • __init__.py
    • instance_v1beta1
      • __init__.py
    • instance_v1
      • __init__.py
    • params_v1beta1
      • __init__.py
    • params_v1
      • __init__.py
    • prediction_v1beta1
      • __init__.py
    • prediction_v1
      • __init__.py

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google/cloud/aiplatform_v1/services/dataset_service/transports/base.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/base.py
+15-27Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.api_core import retry as retries # type: ignore
2626
from google.api_core import operations_v1 # type: ignore
2727
from google.auth import credentials as ga_credentials # type: ignore
28+
from google.oauth2 import service_account # type: ignore
2829

2930
from google.cloud.aiplatform_v1.types import annotation_spec
3031
from google.cloud.aiplatform_v1.types import dataset
@@ -50,8 +51,6 @@
5051
except pkg_resources.DistributionNotFound: # pragma: NO COVER
5152
_GOOGLE_AUTH_VERSION = None
5253

53-
_API_CORE_VERSION = google.api_core.__version__
54-
5554

5655
class DatasetServiceTransport(abc.ABC):
5756
"""Abstract transport class for DatasetService."""
@@ -69,6 +68,7 @@ def __init__(
6968
scopes: Optional[Sequence[str]] = None,
7069
quota_project_id: Optional[str] = None,
7170
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
71+
always_use_jwt_access: Optional[bool] = False,
7272
**kwargs,
7373
) -> None:
7474
"""Instantiate the transport.
@@ -92,6 +92,8 @@ def __init__(
9292
API requests. If ``None``, then default info will be used.
9393
Generally, you only need to set this if you're developing
9494
your own client library.
95+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
96+
be used for service account credentials.
9597
"""
9698
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9799
if ":" not in host:
@@ -101,7 +103,7 @@ def __init__(
101103
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
102104

103105
# Save the scopes.
104-
self._scopes = scopes or self.AUTH_SCOPES
106+
self._scopes = scopes
105107

106108
# If no credentials are provided, then determine the appropriate
107109
# defaults.
@@ -120,13 +122,20 @@ def __init__(
120122
**scopes_kwargs, quota_project_id=quota_project_id
121123
)
122124

125+
# If the credentials is service account credentials, then always try to use self signed JWT.
126+
if (
127+
always_use_jwt_access
128+
and isinstance(credentials, service_account.Credentials)
129+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
130+
):
131+
credentials = credentials.with_always_use_jwt_access(True)
132+
123133
# Save the credentials.
124134
self._credentials = credentials
125135

126-
# TODO(busunkim): These two class methods are in the base transport
136+
# TODO(busunkim): This method is in the base transport
127137
# to avoid duplicating code across the transport classes. These functions
128-
# should be deleted once the minimum required versions of google-api-core
129-
# and google-auth are increased.
138+
# should be deleted once the minimum required versions of google-auth is increased.
130139

131140
# TODO: Remove this function once google-auth >= 1.25.0 is required
132141
@classmethod
@@ -147,27 +156,6 @@ def _get_scopes_kwargs(
147156

148157
return scopes_kwargs
149158

150-
# TODO: Remove this function once google-api-core >= 1.26.0 is required
151-
@classmethod
152-
def _get_self_signed_jwt_kwargs(
153-
cls, host: str, scopes: Optional[Sequence[str]]
154-
) -> Dict[str, Union[Optional[Sequence[str]], str]]:
155-
"""Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
156-
157-
self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {}
158-
159-
if _API_CORE_VERSION and (
160-
packaging.version.parse(_API_CORE_VERSION)
161-
>= packaging.version.parse("1.26.0")
162-
):
163-
self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES
164-
self_signed_jwt_kwargs["scopes"] = scopes
165-
self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST
166-
else:
167-
self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES
168-
169-
return self_signed_jwt_kwargs
170-
171159
def _prep_wrapped_messages(self, client_info):
172160
# Precompute the wrapped methods.
173161
self._wrapped_methods = {
Collapse file

‎google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6161
quota_project_id: Optional[str] = None,
6262
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
63+
always_use_jwt_access: Optional[bool] = False,
6364
) -> None:
6465
"""Instantiate the transport.
6566
@@ -100,6 +101,8 @@ def __init__(
100101
API requests. If ``None``, then default info will be used.
101102
Generally, you only need to set this if you're developing
102103
your own client library.
104+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
105+
be used for service account credentials.
103106
104107
Raises:
105108
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -153,6 +156,7 @@ def __init__(
153156
scopes=scopes,
154157
quota_project_id=quota_project_id,
155158
client_info=client_info,
159+
always_use_jwt_access=always_use_jwt_access,
156160
)
157161

158162
if not self._grpc_channel:
@@ -208,14 +212,14 @@ def create_channel(
208212
and ``credentials_file`` are passed.
209213
"""
210214

211-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
212-
213215
return grpc_helpers.create_channel(
214216
host,
215217
credentials=credentials,
216218
credentials_file=credentials_file,
217219
quota_project_id=quota_project_id,
218-
**self_signed_jwt_kwargs,
220+
default_scopes=cls.AUTH_SCOPES,
221+
scopes=scopes,
222+
default_host=cls.DEFAULT_HOST,
219223
**kwargs,
220224
)
221225

Collapse file

‎google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def create_channel(
8181
aio.Channel: A gRPC AsyncIO channel object.
8282
"""
8383

84-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
85-
8684
return grpc_helpers_async.create_channel(
8785
host,
8886
credentials=credentials,
8987
credentials_file=credentials_file,
9088
quota_project_id=quota_project_id,
91-
**self_signed_jwt_kwargs,
89+
default_scopes=cls.AUTH_SCOPES,
90+
scopes=scopes,
91+
default_host=cls.DEFAULT_HOST,
9292
**kwargs,
9393
)
9494

@@ -106,6 +106,7 @@ def __init__(
106106
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
107107
quota_project_id=None,
108108
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
109+
always_use_jwt_access: Optional[bool] = False,
109110
) -> None:
110111
"""Instantiate the transport.
111112
@@ -147,6 +148,8 @@ def __init__(
147148
API requests. If ``None``, then default info will be used.
148149
Generally, you only need to set this if you're developing
149150
your own client library.
151+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
152+
be used for service account credentials.
150153
151154
Raises:
152155
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -199,6 +202,7 @@ def __init__(
199202
scopes=scopes,
200203
quota_project_id=quota_project_id,
201204
client_info=client_info,
205+
always_use_jwt_access=always_use_jwt_access,
202206
)
203207

204208
if not self._grpc_channel:
Collapse file

‎google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py
+15-27Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from google.api_core import retry as retries # type: ignore
2626
from google.api_core import operations_v1 # type: ignore
2727
from google.auth import credentials as ga_credentials # type: ignore
28+
from google.oauth2 import service_account # type: ignore
2829

2930
from google.cloud.aiplatform_v1.types import endpoint
3031
from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint
@@ -49,8 +50,6 @@
4950
except pkg_resources.DistributionNotFound: # pragma: NO COVER
5051
_GOOGLE_AUTH_VERSION = None
5152

52-
_API_CORE_VERSION = google.api_core.__version__
53-
5453

5554
class EndpointServiceTransport(abc.ABC):
5655
"""Abstract transport class for EndpointService."""
@@ -68,6 +67,7 @@ def __init__(
6867
scopes: Optional[Sequence[str]] = None,
6968
quota_project_id: Optional[str] = None,
7069
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
70+
always_use_jwt_access: Optional[bool] = False,
7171
**kwargs,
7272
) -> None:
7373
"""Instantiate the transport.
@@ -91,6 +91,8 @@ def __init__(
9191
API requests. If ``None``, then default info will be used.
9292
Generally, you only need to set this if you're developing
9393
your own client library.
94+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
95+
be used for service account credentials.
9496
"""
9597
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9698
if ":" not in host:
@@ -100,7 +102,7 @@ def __init__(
100102
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
101103

102104
# Save the scopes.
103-
self._scopes = scopes or self.AUTH_SCOPES
105+
self._scopes = scopes
104106

105107
# If no credentials are provided, then determine the appropriate
106108
# defaults.
@@ -119,13 +121,20 @@ def __init__(
119121
**scopes_kwargs, quota_project_id=quota_project_id
120122
)
121123

124+
# If the credentials is service account credentials, then always try to use self signed JWT.
125+
if (
126+
always_use_jwt_access
127+
and isinstance(credentials, service_account.Credentials)
128+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
129+
):
130+
credentials = credentials.with_always_use_jwt_access(True)
131+
122132
# Save the credentials.
123133
self._credentials = credentials
124134

125-
# TODO(busunkim): These two class methods are in the base transport
135+
# TODO(busunkim): This method is in the base transport
126136
# to avoid duplicating code across the transport classes. These functions
127-
# should be deleted once the minimum required versions of google-api-core
128-
# and google-auth are increased.
137+
# should be deleted once the minimum required versions of google-auth is increased.
129138

130139
# TODO: Remove this function once google-auth >= 1.25.0 is required
131140
@classmethod
@@ -146,27 +155,6 @@ def _get_scopes_kwargs(
146155

147156
return scopes_kwargs
148157

149-
# TODO: Remove this function once google-api-core >= 1.26.0 is required
150-
@classmethod
151-
def _get_self_signed_jwt_kwargs(
152-
cls, host: str, scopes: Optional[Sequence[str]]
153-
) -> Dict[str, Union[Optional[Sequence[str]], str]]:
154-
"""Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version"""
155-
156-
self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {}
157-
158-
if _API_CORE_VERSION and (
159-
packaging.version.parse(_API_CORE_VERSION)
160-
>= packaging.version.parse("1.26.0")
161-
):
162-
self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES
163-
self_signed_jwt_kwargs["scopes"] = scopes
164-
self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST
165-
else:
166-
self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES
167-
168-
return self_signed_jwt_kwargs
169-
170158
def _prep_wrapped_messages(self, client_info):
171159
# Precompute the wrapped methods.
172160
self._wrapped_methods = {
Collapse file

‎google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(
5959
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6060
quota_project_id: Optional[str] = None,
6161
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
62+
always_use_jwt_access: Optional[bool] = False,
6263
) -> None:
6364
"""Instantiate the transport.
6465
@@ -99,6 +100,8 @@ def __init__(
99100
API requests. If ``None``, then default info will be used.
100101
Generally, you only need to set this if you're developing
101102
your own client library.
103+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
104+
be used for service account credentials.
102105
103106
Raises:
104107
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -152,6 +155,7 @@ def __init__(
152155
scopes=scopes,
153156
quota_project_id=quota_project_id,
154157
client_info=client_info,
158+
always_use_jwt_access=always_use_jwt_access,
155159
)
156160

157161
if not self._grpc_channel:
@@ -207,14 +211,14 @@ def create_channel(
207211
and ``credentials_file`` are passed.
208212
"""
209213

210-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
211-
212214
return grpc_helpers.create_channel(
213215
host,
214216
credentials=credentials,
215217
credentials_file=credentials_file,
216218
quota_project_id=quota_project_id,
217-
**self_signed_jwt_kwargs,
219+
default_scopes=cls.AUTH_SCOPES,
220+
scopes=scopes,
221+
default_host=cls.DEFAULT_HOST,
218222
**kwargs,
219223
)
220224

Collapse file

‎google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ def create_channel(
8080
aio.Channel: A gRPC AsyncIO channel object.
8181
"""
8282

83-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
84-
8583
return grpc_helpers_async.create_channel(
8684
host,
8785
credentials=credentials,
8886
credentials_file=credentials_file,
8987
quota_project_id=quota_project_id,
90-
**self_signed_jwt_kwargs,
88+
default_scopes=cls.AUTH_SCOPES,
89+
scopes=scopes,
90+
default_host=cls.DEFAULT_HOST,
9191
**kwargs,
9292
)
9393

@@ -105,6 +105,7 @@ def __init__(
105105
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
106106
quota_project_id=None,
107107
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
108+
always_use_jwt_access: Optional[bool] = False,
108109
) -> None:
109110
"""Instantiate the transport.
110111
@@ -146,6 +147,8 @@ def __init__(
146147
API requests. If ``None``, then default info will be used.
147148
Generally, you only need to set this if you're developing
148149
your own client library.
150+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
151+
be used for service account credentials.
149152
150153
Raises:
151154
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -198,6 +201,7 @@ def __init__(
198201
scopes=scopes,
199202
quota_project_id=quota_project_id,
200203
client_info=client_info,
204+
always_use_jwt_access=always_use_jwt_access,
201205
)
202206

203207
if not self._grpc_channel:

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.