Skip to content

Commit 751ce3f

Browse files
authored
fix: suppress deprecation warning for ADC (#1815)
* fix: suppress deprecation warning for ADC * secret * lint
1 parent 819199a commit 751ce3f

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

google/auth/_default.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,17 @@ def _get_gcloud_sdk_credentials(quota_project_id=None):
305305
_LOGGER.debug("Cloud SDK credentials not found on disk; not using them")
306306
return None, None
307307

308-
credentials, project_id = load_credentials_from_file(
309-
credentials_filename, quota_project_id=quota_project_id
310-
)
311-
credentials._cred_file_path = credentials_filename
308+
with warnings.catch_warnings():
309+
warnings.simplefilter("ignore", DeprecationWarning)
310+
credentials, project_id = load_credentials_from_file(
311+
credentials_filename, quota_project_id=quota_project_id
312+
)
313+
credentials._cred_file_path = credentials_filename
312314

313-
if not project_id:
314-
project_id = _cloud_sdk.get_project_id()
315+
if not project_id:
316+
project_id = _cloud_sdk.get_project_id()
315317

316-
return credentials, project_id
318+
return credentials, project_id
317319

318320

319321
def _get_explicit_environ_credentials(quota_project_id=None):
@@ -339,12 +341,15 @@ def _get_explicit_environ_credentials(quota_project_id=None):
339341
return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
340342

341343
if explicit_file is not None:
342-
credentials, project_id = load_credentials_from_file(
343-
os.environ[environment_vars.CREDENTIALS], quota_project_id=quota_project_id
344-
)
345-
credentials._cred_file_path = f"{explicit_file} file via the GOOGLE_APPLICATION_CREDENTIALS environment variable"
344+
with warnings.catch_warnings():
345+
warnings.simplefilter("ignore", DeprecationWarning)
346+
credentials, project_id = load_credentials_from_file(
347+
os.environ[environment_vars.CREDENTIALS],
348+
quota_project_id=quota_project_id,
349+
)
350+
credentials._cred_file_path = f"{explicit_file} file via the GOOGLE_APPLICATION_CREDENTIALS environment variable"
346351

347-
return credentials, project_id
352+
return credentials, project_id
348353

349354
else:
350355
return None, None

google/auth/_default_async.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io
2121
import json
2222
import os
23+
import warnings
2324

2425
from google.auth import _default
2526
from google.auth import environment_vars
@@ -116,14 +117,16 @@ def _get_gcloud_sdk_credentials(quota_project_id=None):
116117
if not os.path.isfile(credentials_filename):
117118
return None, None
118119

119-
credentials, project_id = load_credentials_from_file(
120-
credentials_filename, quota_project_id=quota_project_id
121-
)
120+
with warnings.catch_warnings():
121+
warnings.simplefilter("ignore", DeprecationWarning)
122+
credentials, project_id = load_credentials_from_file(
123+
credentials_filename, quota_project_id=quota_project_id
124+
)
122125

123-
if not project_id:
124-
project_id = _cloud_sdk.get_project_id()
126+
if not project_id:
127+
project_id = _cloud_sdk.get_project_id()
125128

126-
return credentials, project_id
129+
return credentials, project_id
127130

128131

129132
def _get_explicit_environ_credentials(quota_project_id=None):
@@ -141,11 +144,14 @@ def _get_explicit_environ_credentials(quota_project_id=None):
141144
return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
142145

143146
if explicit_file is not None:
144-
credentials, project_id = load_credentials_from_file(
145-
os.environ[environment_vars.CREDENTIALS], quota_project_id=quota_project_id
146-
)
147+
with warnings.catch_warnings():
148+
warnings.simplefilter("ignore", DeprecationWarning)
149+
credentials, project_id = load_credentials_from_file(
150+
os.environ[environment_vars.CREDENTIALS],
151+
quota_project_id=quota_project_id,
152+
)
147153

148-
return credentials, project_id
154+
return credentials, project_id
149155

150156
else:
151157
return None, None

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)