Skip to content

Commit 8f9c800

Browse files
feat: add always_use_jwt_access (#171)
* 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 7b77c3b commit 8f9c800

10 files changed

Lines changed: 96 additions & 142 deletions

File tree

packages/google-cloud-bigquery-datatransfer/.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/bigquery_datatransfer/__init__.py

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py

Lines changed: 6 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
@@ -861,6 +862,11 @@ async def schedule_transfer_runs(
861862
for a time range.
862863
863864
"""
865+
warnings.warn(
866+
"DataTransferServiceAsyncClient.schedule_transfer_runs is deprecated",
867+
DeprecationWarning,
868+
)
869+
864870
# Create or coerce a protobuf request object.
865871
# Sanity check: If we got a request object, we should *not* have
866872
# gotten any keyword arguments that map to the request.

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py

Lines changed: 6 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
@@ -1020,6 +1021,11 @@ def schedule_transfer_runs(
10201021
for a time range.
10211022
10221023
"""
1024+
warnings.warn(
1025+
"DataTransferServiceClient.schedule_transfer_runs is deprecated",
1026+
DeprecationWarning,
1027+
)
1028+
10231029
# Create or coerce a protobuf request object.
10241030
# Sanity check: If we got a request object, we should *not* have
10251031
# gotten any keyword arguments that map to the request.

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/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.bigquery_datatransfer_v1.types import datatransfer
2930
from google.cloud.bigquery_datatransfer_v1.types import transfer
@@ -47,8 +48,6 @@
4748
except pkg_resources.DistributionNotFound: # pragma: NO COVER
4849
_GOOGLE_AUTH_VERSION = None
4950

50-
_API_CORE_VERSION = google.api_core.__version__
51-
5251

5352
class DataTransferServiceTransport(abc.ABC):
5453
"""Abstract transport class for DataTransferService."""
@@ -66,6 +65,7 @@ def __init__(
6665
scopes: Optional[Sequence[str]] = None,
6766
quota_project_id: Optional[str] = None,
6867
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
68+
always_use_jwt_access: Optional[bool] = False,
6969
**kwargs,
7070
) -> None:
7171
"""Instantiate the transport.
@@ -89,6 +89,8 @@ def __init__(
8989
API requests. If ``None``, then default info will be used.
9090
Generally, you only need to set this if you're developing
9191
your own client library.
92+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
93+
be used for service account credentials.
9294
"""
9395
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
9496
if ":" not in host:
@@ -98,7 +100,7 @@ def __init__(
98100
scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
99101

100102
# Save the scopes.
101-
self._scopes = scopes or self.AUTH_SCOPES
103+
self._scopes = scopes
102104

103105
# If no credentials are provided, then determine the appropriate
104106
# defaults.
@@ -117,13 +119,20 @@ def __init__(
117119
**scopes_kwargs, quota_project_id=quota_project_id
118120
)
119121

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

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

128137
# TODO: Remove this function once google-auth >= 1.25.0 is required
129138
@classmethod
@@ -144,27 +153,6 @@ def _get_scopes_kwargs(
144153

145154
return scopes_kwargs
146155

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

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/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
@@ -154,6 +157,7 @@ def __init__(
154157
scopes=scopes,
155158
quota_project_id=quota_project_id,
156159
client_info=client_info,
160+
always_use_jwt_access=always_use_jwt_access,
157161
)
158162

159163
if not self._grpc_channel:
@@ -209,14 +213,14 @@ def create_channel(
209213
and ``credentials_file`` are passed.
210214
"""
211215

212-
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
213-
214216
return grpc_helpers.create_channel(
215217
host,
216218
credentials=credentials,
217219
credentials_file=credentials_file,
218220
quota_project_id=quota_project_id,
219-
**self_signed_jwt_kwargs,
221+
default_scopes=cls.AUTH_SCOPES,
222+
scopes=scopes,
223+
default_host=cls.DEFAULT_HOST,
220224
**kwargs,
221225
)
222226

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/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
@@ -200,6 +203,7 @@ def __init__(
200203
scopes=scopes,
201204
quota_project_id=quota_project_id,
202205
client_info=client_info,
206+
always_use_jwt_access=always_use_jwt_access,
203207
)
204208

205209
if not self._grpc_channel:

packages/google-cloud-bigquery-datatransfer/owlbot.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,12 @@
2727
# ----------------------------------------------------------------------------
2828
for library in s.get_staging_dirs("v1"):
2929

30-
# Comment out broken assertion in unit test
31-
# https://github.com/googleapis/gapic-generator-python/issues/897
30+
# Fix incorrect DeprecationWarning
31+
# Fixed in https://github.com/googleapis/gapic-generator-python/pull/943
3232
s.replace(
33-
library / "tests/**/*.py",
34-
"assert args\[0\]\.start_time == timestamp_pb2\.Timestamp\(seconds=751\)",
35-
"# assert args[0].start_time == timestamp_pb2.Timestamp(seconds=751)"
36-
)
37-
s.replace(
38-
library / "tests/**/*.py",
39-
"assert args\[0\]\.end_time == timestamp_pb2\.Timestamp\(seconds=751\)",
40-
"# assert args[0].end_time == timestamp_pb2.Timestamp(seconds=751)"
33+
"google/**/*client.py",
34+
"warnings\.DeprecationWarning",
35+
"DeprecationWarning"
4136
)
4237

4338
s.move(library, excludes=["*.tar.gz", "docs/index.rst", "README.rst", "setup.py"])

packages/google-cloud-bigquery-datatransfer/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# 'Development Status :: 5 - Production/Stable'
3030
release_status = "Development Status :: 5 - Production/Stable"
3131
dependencies = (
32-
"google-api-core[grpc] >= 1.22.2, < 2.0.0dev",
32+
"google-api-core[grpc] >= 1.26.0, <2.0.0dev",
3333
"proto-plus >= 1.15.0",
3434
"packaging >= 14.3",
3535
)

packages/google-cloud-bigquery-datatransfer/testing/constraints-3.6.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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.22.2
8+
google-api-core==1.26.0
99
proto-plus==1.15.0
1010
libcst==0.2.5
1111
packaging==14.3

0 commit comments

Comments
 (0)