Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit155da5e

Browse files
authored
fix: require google-auth>=1.25.0 (#190)
1 parentc4ff747 commit155da5e

File tree

5 files changed

+44
-190
lines changed

5 files changed

+44
-190
lines changed

‎google/api_core/grpc_helpers.py‎

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
importcollections
1818

1919
importgrpc
20-
frompackagingimportversion
2120
importpkg_resources
2221
importsix
2322

@@ -44,11 +43,6 @@
4443
exceptpkg_resources.DistributionNotFound:# pragma: NO COVER
4544
_GOOGLE_AUTH_VERSION=None
4645

47-
if_GOOGLE_AUTH_VERSIONisnotNoneandversion.parse(_GOOGLE_AUTH_VERSION)>=version.parse("1.25.0"):
48-
_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST=True
49-
else:
50-
_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST=False
51-
5246
# The list of gRPC Callable interfaces that return iterators.
5347
_STREAM_WRAP_CLASSES= (grpc.UnaryStreamMultiCallable,grpc.StreamStreamMultiCallable)
5448

@@ -232,55 +226,29 @@ def _create_composite_credentials(
232226
)
233227

234228
ifcredentials_file:
235-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
236-
if_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
237-
credentials,_=google.auth.load_credentials_from_file(
238-
credentials_file,
239-
scopes=scopes,
240-
default_scopes=default_scopes
241-
)
242-
else:
243-
credentials,_=google.auth.load_credentials_from_file(
244-
credentials_file,
245-
scopes=scopesordefault_scopes,
246-
)
229+
credentials,_=google.auth.load_credentials_from_file(
230+
credentials_file,
231+
scopes=scopes,
232+
default_scopes=default_scopes
233+
)
247234
elifcredentials:
248-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
249-
if_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
250-
credentials=google.auth.credentials.with_scopes_if_required(
251-
credentials,
252-
scopes=scopes,
253-
default_scopes=default_scopes
254-
)
255-
else:
256-
credentials=google.auth.credentials.with_scopes_if_required(
257-
credentials,
258-
scopes=scopesordefault_scopes,
259-
)
260-
235+
credentials=google.auth.credentials.with_scopes_if_required(
236+
credentials,
237+
scopes=scopes,
238+
default_scopes=default_scopes
239+
)
261240
else:
262-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
263-
if_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
264-
credentials,_=google.auth.default(scopes=scopes,default_scopes=default_scopes)
265-
else:
266-
credentials,_=google.auth.default(scopes=scopesordefault_scopes)
241+
credentials,_=google.auth.default(scopes=scopes,default_scopes=default_scopes)
267242

268243
ifquota_project_idandisinstance(credentials,google.auth.credentials.CredentialsWithQuotaProject):
269244
credentials=credentials.with_quota_project(quota_project_id)
270245

271246
request=google.auth.transport.requests.Request()
272247

273248
# Create the metadata plugin for inserting the authorization header.
274-
275-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
276-
if_GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
277-
metadata_plugin=google.auth.transport.grpc.AuthMetadataPlugin(
278-
credentials,request,default_host=default_host,
279-
)
280-
else:
281-
metadata_plugin=google.auth.transport.grpc.AuthMetadataPlugin(
282-
credentials,request
283-
)
249+
metadata_plugin=google.auth.transport.grpc.AuthMetadataPlugin(
250+
credentials,request,default_host=default_host,
251+
)
284252

285253
# Create a set of grpc.CallCredentials using the metadata plugin.
286254
google_auth_credentials=grpc.metadata_call_credentials(metadata_plugin)

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
dependencies= [
3232
"googleapis-common-protos >= 1.6.0, < 2.0dev",
3333
"protobuf >= 3.12.0",
34-
"google-auth >= 1.21.1, < 2.0dev",
34+
"google-auth >= 1.25.0, < 2.0dev",
3535
"requests >= 2.18.0, < 3.0.0dev",
3636
"setuptools >= 40.3.0",
3737
"packaging >= 14.3",

‎testing/constraints-3.6.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Then this file should have foo==1.14.0
88
googleapis-common-protos==1.6.0
99
protobuf==3.12.0
10-
google-auth==1.21.1
10+
google-auth==1.25.0
1111
requests==2.18.0
1212
setuptools==40.3.0
1313
packaging==14.3

‎tests/asyncio/test_grpc_helpers_async.py‎

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
importpytest
1919

2020
fromgoogle.api_coreimportexceptions
21-
fromgoogle.api_coreimportgrpc_helpers
2221
fromgoogle.api_coreimportgrpc_helpers_async
2322
importgoogle.auth.credentials
2423

@@ -276,11 +275,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c
276275

277276
assertchannelisgrpc_secure_channel.return_value
278277

279-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
280-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
281-
default.assert_called_once_with(scopes=None,default_scopes=None)
282-
else:
283-
default.assert_called_once_with(scopes=None)
278+
default.assert_called_once_with(scopes=None,default_scopes=None)
284279
grpc_secure_channel.assert_called_once_with(target,composite_creds)
285280

286281

@@ -306,14 +301,8 @@ def test_create_channel_implicit_with_default_host(grpc_secure_channel, default,
306301

307302
assertchannelisgrpc_secure_channel.return_value
308303

309-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
310-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
311-
default.assert_called_once_with(scopes=None,default_scopes=None)
312-
auth_metadata_plugin.assert_called_once_with(mock.sentinel.credentials,mock.sentinel.Request,default_host=default_host)
313-
else:
314-
default.assert_called_once_with(scopes=None)
315-
auth_metadata_plugin.assert_called_once_with(mock.sentinel.credentials,mock.sentinel.Request)
316-
304+
default.assert_called_once_with(scopes=None,default_scopes=None)
305+
auth_metadata_plugin.assert_called_once_with(mock.sentinel.credentials,mock.sentinel.Request,default_host=default_host)
317306
grpc_secure_channel.assert_called_once_with(target,composite_creds)
318307

319308

@@ -332,12 +321,7 @@ def test_create_channel_implicit_with_ssl_creds(
332321

333322
grpc_helpers_async.create_channel(target,ssl_credentials=ssl_creds)
334323

335-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
336-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
337-
default.assert_called_once_with(scopes=None,default_scopes=None)
338-
else:
339-
default.assert_called_once_with(scopes=None)
340-
324+
default.assert_called_once_with(scopes=None,default_scopes=None)
341325
composite_creds_call.assert_called_once_with(ssl_creds,mock.ANY)
342326
composite_creds=composite_creds_call.return_value
343327
grpc_secure_channel.assert_called_once_with(target,composite_creds)
@@ -360,12 +344,7 @@ def test_create_channel_implicit_with_scopes(
360344

361345
assertchannelisgrpc_secure_channel.return_value
362346

363-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
364-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
365-
default.assert_called_once_with(scopes=["one","two"],default_scopes=None)
366-
else:
367-
default.assert_called_once_with(scopes=["one","two"])
368-
347+
default.assert_called_once_with(scopes=["one","two"],default_scopes=None)
369348
grpc_secure_channel.assert_called_once_with(target,composite_creds)
370349

371350

@@ -386,12 +365,7 @@ def test_create_channel_implicit_with_default_scopes(
386365

387366
assertchannelisgrpc_secure_channel.return_value
388367

389-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
390-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
391-
default.assert_called_once_with(scopes=None,default_scopes=["three","four"])
392-
else:
393-
default.assert_called_once_with(scopes=["three","four"])
394-
368+
default.assert_called_once_with(scopes=None,default_scopes=["three","four"])
395369
grpc_secure_channel.assert_called_once_with(target,composite_creds)
396370

397371

@@ -417,12 +391,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred
417391

418392
channel=grpc_helpers_async.create_channel(target,credentials=mock.sentinel.credentials)
419393

420-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
421-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
422-
auth_creds.assert_called_once_with(mock.sentinel.credentials,scopes=None,default_scopes=None)
423-
else:
424-
auth_creds.assert_called_once_with(mock.sentinel.credentials,scopes=None)
425-
394+
auth_creds.assert_called_once_with(mock.sentinel.credentials,scopes=None,default_scopes=None)
426395
assertchannelisgrpc_secure_channel.return_value
427396
grpc_secure_channel.assert_called_once_with(target,composite_creds)
428397

@@ -440,12 +409,8 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal
440409
channel=grpc_helpers_async.create_channel(
441410
target,credentials=credentials,scopes=scopes
442411
)
443-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
444-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
445-
credentials.with_scopes.assert_called_once_with(scopes,default_scopes=None)
446-
else:
447-
credentials.with_scopes.assert_called_once_with(scopes)
448412

413+
credentials.with_scopes.assert_called_once_with(scopes,default_scopes=None)
449414
assertchannelisgrpc_secure_channel.return_value
450415
grpc_secure_channel.assert_called_once_with(target,composite_creds)
451416

@@ -464,12 +429,7 @@ def test_create_channel_explicit_default_scopes(grpc_secure_channel, composite_c
464429
target,credentials=credentials,default_scopes=default_scopes
465430
)
466431

467-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
468-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
469-
credentials.with_scopes.assert_called_once_with(scopes=None,default_scopes=default_scopes)
470-
else:
471-
credentials.with_scopes.assert_called_once_with(scopes=default_scopes)
472-
432+
credentials.with_scopes.assert_called_once_with(scopes=None,default_scopes=default_scopes)
473433
assertchannelisgrpc_secure_channel.return_value
474434
grpc_secure_channel.assert_called_once_with(target,composite_creds)
475435

@@ -508,12 +468,7 @@ def test_create_channnel_with_credentials_file(load_credentials_from_file, grpc_
508468
target,credentials_file=credentials_file
509469
)
510470

511-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
512-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
513-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=None,default_scopes=None)
514-
else:
515-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=None)
516-
471+
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=None,default_scopes=None)
517472
assertchannelisgrpc_secure_channel.return_value
518473
grpc_secure_channel.assert_called_once_with(target,composite_creds)
519474

@@ -536,12 +491,7 @@ def test_create_channel_with_credentials_file_and_scopes(load_credentials_from_f
536491
target,credentials_file=credentials_file,scopes=scopes
537492
)
538493

539-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
540-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
541-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=scopes,default_scopes=None)
542-
else:
543-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=scopes)
544-
494+
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=scopes,default_scopes=None)
545495
assertchannelisgrpc_secure_channel.return_value
546496
grpc_secure_channel.assert_called_once_with(target,composite_creds)
547497

@@ -564,12 +514,7 @@ def test_create_channel_with_credentials_file_and_default_scopes(load_credential
564514
target,credentials_file=credentials_file,default_scopes=default_scopes
565515
)
566516

567-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
568-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
569-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=None,default_scopes=default_scopes)
570-
else:
571-
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=default_scopes)
572-
517+
google.auth.load_credentials_from_file.assert_called_once_with(credentials_file,scopes=None,default_scopes=default_scopes)
573518
assertchannelisgrpc_secure_channel.return_value
574519
grpc_secure_channel.assert_called_once_with(target,composite_creds)
575520

@@ -585,12 +530,7 @@ def test_create_channel_without_grpc_gcp(grpc_secure_channel):
585530

586531
grpc_helpers_async.create_channel(target,credentials=credentials,scopes=scopes)
587532
grpc_secure_channel.assert_called()
588-
589-
# TODO: remove this if/else once google-auth >= 1.25.0 is required
590-
ifgrpc_helpers._GOOGLE_AUTH_HAS_DEFAULT_SCOPES_AND_DEFAULT_HOST:
591-
credentials.with_scopes.assert_called_once_with(scopes,default_scopes=None)
592-
else:
593-
credentials.with_scopes.assert_called_once_with(scopes)
533+
credentials.with_scopes.assert_called_once_with(scopes,default_scopes=None)
594534

595535

596536
@pytest.mark.asyncio

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp