Skip to content

Commit 65c3ad0

Browse files
feat: add always_use_jwt_access (#31)
* chore: use gapic-generator-python 0.50.3 Committer: @busunkim96 PiperOrigin-RevId: 382142900 Source-Link: googleapis/googleapis@513440f Source-Link: googleapis/googleapis-gen@7b1e2c3
1 parent 2ee5678 commit 65c3ad0

File tree

10 files changed

+97
-149
lines changed

10 files changed

+97
-149
lines changed

packages/google-cloud-service-management/.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
branch = True
33

44
[report]
5-
fail_under = 100
65
show_missing = True
76
omit =
87
google/cloud/servicemanagement/__init__.py

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/async_client.py

Lines changed: 11 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
@@ -1443,6 +1444,11 @@ async def enable_service(
14431444
Operation payload for EnableService method.
14441445
14451446
"""
1447+
warnings.warn(
1448+
"ServiceManagerAsyncClient.enable_service is deprecated",
1449+
DeprecationWarning,
1450+
)
1451+
14461452
# Create or coerce a protobuf request object.
14471453
# Sanity check: If we got a request object, we should *not* have
14481454
# gotten any keyword arguments that map to the request.
@@ -1544,6 +1550,11 @@ async def disable_service(
15441550
Operation payload for DisableService method.
15451551
15461552
"""
1553+
warnings.warn(
1554+
"ServiceManagerAsyncClient.disable_service is deprecated",
1555+
DeprecationWarning,
1556+
)
1557+
15471558
# Create or coerce a protobuf request object.
15481559
# Sanity check: If we got a request object, we should *not* have
15491560
# gotten any keyword arguments that map to the request.

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/client.py

Lines changed: 9 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
@@ -1614,6 +1615,10 @@ def enable_service(
16141615
Operation payload for EnableService method.
16151616
16161617
"""
1618+
warnings.warn(
1619+
"ServiceManagerClient.enable_service is deprecated", DeprecationWarning,
1620+
)
1621+
16171622
# Create or coerce a protobuf request object.
16181623
# Sanity check: If we got a request object, we should *not* have
16191624
# gotten any keyword arguments that map to the request.
@@ -1715,6 +1720,10 @@ def disable_service(
17151720
Operation payload for DisableService method.
17161721
17171722
"""
1723+
warnings.warn(
1724+
"ServiceManagerClient.disable_service is deprecated", DeprecationWarning,
1725+
)
1726+
17181727
# Create or coerce a protobuf request object.
17191728
# Sanity check: If we got a request object, we should *not* have
17201729
# gotten any keyword arguments that map to the request.

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/transports/base.py

Lines 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.api import service_pb2 # type: ignore
3031
from google.cloud.servicemanagement_v1.types import resources
@@ -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 ServiceManagerTransport(abc.ABC):
5655
"""Abstract transport class for ServiceManager."""
@@ -73,6 +72,7 @@ def __init__(
7372
scopes: Optional[Sequence[str]] = None,
7473
quota_project_id: Optional[str] = None,
7574
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
75+
always_use_jwt_access: Optional[bool] = False,
7676
**kwargs,
7777
) -> None:
7878
"""Instantiate the transport.
@@ -96,6 +96,8 @@ def __init__(
9696
API requests. If ``None``, then default info will be used.
9797
Generally, you only need to set this if you're developing
9898
your own client library.
99+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
100+
be used for service account credentials.
99101
"""
100102
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
101103
if ":" not in host:
@@ -105,7 +107,7 @@ def __init__(
105107
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
106108

107109
# Save the scopes.
108-
self._scopes = scopes or self.AUTH_SCOPES
110+
self._scopes = scopes
109111

110112
# If no credentials are provided, then determine the appropriate
111113
# defaults.
@@ -124,13 +126,20 @@ def __init__(
124126
**scopes_kwargs, quota_project_id=quota_project_id
125127
)
126128

129+
# If the credentials is service account credentials, then always try to use self signed JWT.
130+
if (
131+
always_use_jwt_access
132+
and isinstance(credentials, service_account.Credentials)
133+
and hasattr(service_account.Credentials, "with_always_use_jwt_access")
134+
):
135+
credentials = credentials.with_always_use_jwt_access(True)
136+
127137
# Save the credentials.
128138
self._credentials = credentials
129139

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

135144
# TODO: Remove this function once google-auth >= 1.25.0 is required
136145
@classmethod
@@ -151,27 +160,6 @@ def _get_scopes_kwargs(
151160

152161
return scopes_kwargs
153162

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

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6363
quota_project_id: Optional[str] = None,
6464
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
65+
always_use_jwt_access: Optional[bool] = False,
6566
) -> None:
6667
"""Instantiate the transport.
6768
@@ -102,6 +103,8 @@ def __init__(
102103
API requests. If ``None``, then default info will be used.
103104
Generally, you only need to set this if you're developing
104105
your own client library.
106+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
107+
be used for service account credentials.
105108
106109
Raises:
107110
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -155,6 +158,7 @@ def __init__(
155158
scopes=scopes,
156159
quota_project_id=quota_project_id,
157160
client_info=client_info,
161+
always_use_jwt_access=always_use_jwt_access,
158162
)
159163

160164
if not self._grpc_channel:
@@ -210,14 +214,14 @@ def create_channel(
210214
and ``credentials_file`` are passed.
211215
"""
212216

213-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
214-
215217
return grpc_helpers.create_channel(
216218
host,
217219
credentials=credentials,
218220
credentials_file=credentials_file,
219221
quota_project_id=quota_project_id,
220-
**self_signed_jwt_kwargs,
222+
default_scopes=cls.AUTH_SCOPES,
223+
scopes=scopes,
224+
default_host=cls.DEFAULT_HOST,
221225
**kwargs,
222226
)
223227

packages/google-cloud-service-management/google/cloud/servicemanagement_v1/services/service_manager/transports/grpc_asyncio.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def create_channel(
8383
aio.Channel: A gRPC AsyncIO channel object.
8484
"""
8585

86-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
87-
8886
return grpc_helpers_async.create_channel(
8987
host,
9088
credentials=credentials,
9189
credentials_file=credentials_file,
9290
quota_project_id=quota_project_id,
93-
**self_signed_jwt_kwargs,
91+
default_scopes=cls.AUTH_SCOPES,
92+
scopes=scopes,
93+
default_host=cls.DEFAULT_HOST,
9494
**kwargs,
9595
)
9696

@@ -108,6 +108,7 @@ def __init__(
108108
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
109109
quota_project_id=None,
110110
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
111+
always_use_jwt_access: Optional[bool] = False,
111112
) -> None:
112113
"""Instantiate the transport.
113114
@@ -149,6 +150,8 @@ def __init__(
149150
API requests. If ``None``, then default info will be used.
150151
Generally, you only need to set this if you're developing
151152
your own client library.
153+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
154+
be used for service account credentials.
152155
153156
Raises:
154157
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -201,6 +204,7 @@ def __init__(
201204
scopes=scopes,
202205
quota_project_id=quota_project_id,
203206
client_info=client_info,
207+
always_use_jwt_access=always_use_jwt_access,
204208
)
205209

206210
if not self._grpc_channel:

packages/google-cloud-service-management/owlbot.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
for library in s.get_staging_dirs(default_version):
2828
s.move(library, excludes=["setup.py", "README.rst", "docs/index.rst"])
2929

30+
# Fix DeprecationWarning
31+
# Fix incorrect DeprecationWarning
32+
# Fixed in https://github.com/googleapis/gapic-generator-python/pull/943
33+
s.replace(
34+
"google/**/*client.py",
35+
"warnings\.DeprecationWarning",
36+
"DeprecationWarning"
37+
)
38+
3039
s.remove_staging_dirs()
3140

3241
# ----------------------------------------------------------------------------
@@ -41,4 +50,4 @@
4150
templated_files, excludes=excludes
4251
)
4352

44-
s.shell.run(["nox", "-s", "blacken"], hide_output=False)
53+
s.shell.run(["nox", "-s", "blacken"], hide_output=False)

packages/google-cloud-service-management/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
release_status = "Development Status :: 5 - Production/Stable"
2626
url = "https://github.com/googleapis/python-service-management"
2727
dependencies = [
28-
"google-api-core[grpc] >= 1.22.2, < 2.0.0dev",
28+
"google-api-core[grpc] >= 1.26.0, <2.0.0dev",
2929
"libcst >= 0.2.5",
3030
"proto-plus >= 1.15.0",
3131
"packaging >= 14.3",

packages/google-cloud-service-management/testing/constraints-3.6.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev",
2121
# Then this file should have foo==1.14.0
22-
google-api-core==1.22.2
22+
google-api-core==1.26.0
2323
libcst==0.2.5
2424
proto-plus==1.15.0
2525
packaging==14.3

0 commit comments

Comments
 (0)