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

Commit bb598c4

Browse files
feat: add always_use_jwt_access (#119)
* chore: use gapic-generator-python 0.50.3 Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: https://github.com/googleapis/googleapis-gen/commit/7b1e2c31233f79a704ec21ca410bf661d6bc68d0 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/master/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Bu Sun Kim <[email protected]>
1 parent d1a1668 commit bb598c4

File tree

15 files changed

+161
-252
lines changed

15 files changed

+161
-252
lines changed

google/cloud/container_v1/services/cluster_manager/async_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from typing import Dict, Sequence, Tuple, Type, Union
2020
import pkg_resources
21+
import warnings
2122

2223
import google.api_core.client_options as ClientOptions # type: ignore
2324
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -1210,6 +1211,10 @@ async def set_locations(
12101211
output only.
12111212
12121213
"""
1214+
warnings.warn(
1215+
"ClusterManagerAsyncClient.set_locations is deprecated", DeprecationWarning,
1216+
)
1217+
12131218
# Create or coerce a protobuf request object.
12141219
# Sanity check: If we got a request object, we should *not* have
12151220
# gotten any keyword arguments that map to the request.

google/cloud/container_v1/services/cluster_manager/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
2121
import pkg_resources
22+
import warnings
2223

2324
from google.api_core import client_options as client_options_lib # type: ignore
2425
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -1365,6 +1366,10 @@ def set_locations(
13651366
output only.
13661367
13671368
"""
1369+
warnings.warn(
1370+
"ClusterManagerClient.set_locations is deprecated", DeprecationWarning,
1371+
)
1372+
13681373
# Create or coerce a protobuf request object.
13691374
# Sanity check: If we got a request object, we should *not* have
13701375
# gotten any keyword arguments that map to the request.

google/cloud/container_v1/services/cluster_manager/transports/base.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from google.api_core import gapic_v1 # type: ignore
2525
from google.api_core import retry as retries # type: ignore
2626
from google.auth import credentials as ga_credentials # type: ignore
27+
from google.oauth2 import service_account # type: ignore
2728

2829
from google.cloud.container_v1.types import cluster_service
2930
from google.protobuf import empty_pb2 # type: ignore
@@ -44,8 +45,6 @@
4445
except pkg_resources.DistributionNotFound: # pragma: NO COVER
4546
_GOOGLE_AUTH_VERSION = None
4647

47-
_API_CORE_VERSION = google.api_core.__version__
48-
4948

5049
class ClusterManagerTransport(abc.ABC):
5150
"""Abstract transport class for ClusterManager."""
@@ -63,6 +62,7 @@ def __init__(
6362
scopes: Optional[Sequence[str]] = None,
6463
quota_project_id: Optional[str] = None,
6564
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
65+
always_use_jwt_access: Optional[bool] = False,
6666
**kwargs,
6767
) -> None:
6868
"""Instantiate the transport.
@@ -86,6 +86,8 @@ def __init__(
8686
API requests. If ``None``, then default info will be used.
8787
Generally, you only need to set this if you're developing
8888
your own client library.
89+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
90+
be used for service account credentials.
8991
"""
9092
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9193
if ":" not in host:
@@ -95,7 +97,7 @@ def __init__(
9597
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
9698

9799
# Save the scopes.
98-
self._scopes = scopes or self.AUTH_SCOPES
100+
self._scopes = scopes
99101

100102
# If no credentials are provided, then determine the appropriate
101103
# defaults.
@@ -114,13 +116,20 @@ def __init__(
114116
**scopes_kwargs, quota_project_id=quota_project_id
115117
)
116118

119+
# If the credentials is service account credentials, then always try to use self signed JWT.
120+
if (
121+
always_use_jwt_access
122+
and isinstance(credentials, service_account.Credentials)
123+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
124+
):
125+
credentials = credentials.with_always_use_jwt_access(True)
126+
117127
# Save the credentials.
118128
self._credentials = credentials
119129

120-
# TODO(busunkim): These two class methods are in the base transport
130+
# TODO(busunkim): This method is in the base transport
121131
# to avoid duplicating code across the transport classes. These functions
122-
# should be deleted once the minimum required versions of google-api-core
123-
# and google-auth are increased.
132+
# should be deleted once the minimum required versions of google-auth is increased.
124133

125134
# TODO: Remove this function once google-auth >= 1.25.0 is required
126135
@classmethod
@@ -141,27 +150,6 @@ def _get_scopes_kwargs(
141150

142151
return scopes_kwargs
143152

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

google/cloud/container_v1/services/cluster_manager/transports/grpc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
61+
always_use_jwt_access: Optional[bool] = False,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -98,6 +99,8 @@ def __init__(
9899
API requests. If ``None``, then default info will be used.
99100
Generally, you only need to set this if you're developing
100101
your own client library.
102+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
103+
be used for service account credentials.
101104
102105
Raises:
103106
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,6 +153,7 @@ def __init__(
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
156+
always_use_jwt_access=always_use_jwt_access,
153157
)
154158

155159
if not self._grpc_channel:
@@ -205,14 +209,14 @@ def create_channel(
205209
and ``credentials_file`` are passed.
206210
"""
207211

208-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
209-
210212
return grpc_helpers.create_channel(
211213
host,
212214
credentials=credentials,
213215
credentials_file=credentials_file,
214216
quota_project_id=quota_project_id,
215-
**self_signed_jwt_kwargs,
217+
default_scopes=cls.AUTH_SCOPES,
218+
scopes=scopes,
219+
default_host=cls.DEFAULT_HOST,
216220
**kwargs,
217221
)
218222

google/cloud/container_v1/services/cluster_manager/transports/grpc_asyncio.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ def create_channel(
7979
aio.Channel: A gRPC AsyncIO channel object.
8080
"""
8181

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

@@ -104,6 +104,7 @@ def __init__(
104104
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
105105
quota_project_id=None,
106106
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
107+
always_use_jwt_access: Optional[bool] = False,
107108
) -> None:
108109
"""Instantiate the transport.
109110
@@ -145,6 +146,8 @@ def __init__(
145146
API requests. If ``None``, then default info will be used.
146147
Generally, you only need to set this if you're developing
147148
your own client library.
149+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
150+
be used for service account credentials.
148151
149152
Raises:
150153
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -196,6 +199,7 @@ def __init__(
196199
scopes=scopes,
197200
quota_project_id=quota_project_id,
198201
client_info=client_info,
202+
always_use_jwt_access=always_use_jwt_access,
199203
)
200204

201205
if not self._grpc_channel:

google/cloud/container_v1beta1/services/cluster_manager/async_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from typing import Dict, Sequence, Tuple, Type, Union
2020
import pkg_resources
21+
import warnings
2122

2223
import google.api_core.client_options as ClientOptions # type: ignore
2324
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -1130,6 +1131,10 @@ async def set_locations(
11301131
output only.
11311132
11321133
"""
1134+
warnings.warn(
1135+
"ClusterManagerAsyncClient.set_locations is deprecated", DeprecationWarning,
1136+
)
1137+
11331138
# Create or coerce a protobuf request object.
11341139
# Sanity check: If we got a request object, we should *not* have
11351140
# gotten any keyword arguments that map to the request.

google/cloud/container_v1beta1/services/cluster_manager/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
2121
import pkg_resources
22+
import warnings
2223

2324
from google.api_core import client_options as client_options_lib # type: ignore
2425
from google.api_core import exceptions as core_exceptions # type: ignore
@@ -1294,6 +1295,10 @@ def set_locations(
12941295
output only.
12951296
12961297
"""
1298+
warnings.warn(
1299+
"ClusterManagerClient.set_locations is deprecated", DeprecationWarning,
1300+
)
1301+
12971302
# Create or coerce a protobuf request object.
12981303
# Sanity check: If we got a request object, we should *not* have
12991304
# gotten any keyword arguments that map to the request.

google/cloud/container_v1beta1/services/cluster_manager/transports/base.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from google.api_core import gapic_v1 # type: ignore
2525
from google.api_core import retry as retries # type: ignore
2626
from google.auth import credentials as ga_credentials # type: ignore
27+
from google.oauth2 import service_account # type: ignore
2728

2829
from google.cloud.container_v1beta1.types import cluster_service
2930
from google.protobuf import empty_pb2 # type: ignore
@@ -44,8 +45,6 @@
4445
except pkg_resources.DistributionNotFound: # pragma: NO COVER
4546
_GOOGLE_AUTH_VERSION = None
4647

47-
_API_CORE_VERSION = google.api_core.__version__
48-
4948

5049
class ClusterManagerTransport(abc.ABC):
5150
"""Abstract transport class for ClusterManager."""
@@ -63,6 +62,7 @@ def __init__(
6362
scopes: Optional[Sequence[str]] = None,
6463
quota_project_id: Optional[str] = None,
6564
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
65+
always_use_jwt_access: Optional[bool] = False,
6666
**kwargs,
6767
) -> None:
6868
"""Instantiate the transport.
@@ -86,6 +86,8 @@ def __init__(
8686
API requests. If ``None``, then default info will be used.
8787
Generally, you only need to set this if you're developing
8888
your own client library.
89+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
90+
be used for service account credentials.
8991
"""
9092
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9193
if ":" not in host:
@@ -95,7 +97,7 @@ def __init__(
9597
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
9698

9799
# Save the scopes.
98-
self._scopes = scopes or self.AUTH_SCOPES
100+
self._scopes = scopes
99101

100102
# If no credentials are provided, then determine the appropriate
101103
# defaults.
@@ -114,13 +116,20 @@ def __init__(
114116
**scopes_kwargs, quota_project_id=quota_project_id
115117
)
116118

119+
# If the credentials is service account credentials, then always try to use self signed JWT.
120+
if (
121+
always_use_jwt_access
122+
and isinstance(credentials, service_account.Credentials)
123+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
124+
):
125+
credentials = credentials.with_always_use_jwt_access(True)
126+
117127
# Save the credentials.
118128
self._credentials = credentials
119129

120-
# TODO(busunkim): These two class methods are in the base transport
130+
# TODO(busunkim): This method is in the base transport
121131
# to avoid duplicating code across the transport classes. These functions
122-
# should be deleted once the minimum required versions of google-api-core
123-
# and google-auth are increased.
132+
# should be deleted once the minimum required versions of google-auth is increased.
124133

125134
# TODO: Remove this function once google-auth >= 1.25.0 is required
126135
@classmethod
@@ -141,27 +150,6 @@ def _get_scopes_kwargs(
141150

142151
return scopes_kwargs
143152

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

google/cloud/container_v1beta1/services/cluster_manager/transports/grpc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5959
quota_project_id: Optional[str] = None,
6060
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
61+
always_use_jwt_access: Optional[bool] = False,
6162
) -> None:
6263
"""Instantiate the transport.
6364
@@ -98,6 +99,8 @@ def __init__(
9899
API requests. If ``None``, then default info will be used.
99100
Generally, you only need to set this if you're developing
100101
your own client library.
102+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
103+
be used for service account credentials.
101104
102105
Raises:
103106
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,6 +153,7 @@ def __init__(
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
156+
always_use_jwt_access=always_use_jwt_access,
153157
)
154158

155159
if not self._grpc_channel:
@@ -205,14 +209,14 @@ def create_channel(
205209
and ``credentials_file`` are passed.
206210
"""
207211

208-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
209-
210212
return grpc_helpers.create_channel(
211213
host,
212214
credentials=credentials,
213215
credentials_file=credentials_file,
214216
quota_project_id=quota_project_id,
215-
**self_signed_jwt_kwargs,
217+
default_scopes=cls.AUTH_SCOPES,
218+
scopes=scopes,
219+
default_host=cls.DEFAULT_HOST,
216220
**kwargs,
217221
)
218222

0 commit comments

Comments
 (0)