chore: blacken (#375)
diff --git a/google/auth/_default.py b/google/auth/_default.py
index 27de58d..32e81ba 100644
--- a/google/auth/_default.py
+++ b/google/auth/_default.py
@@ -32,8 +32,8 @@
_LOGGER = logging.getLogger(__name__)
# Valid types accepted for file-based credentials.
-_AUTHORIZED_USER_TYPE = 'authorized_user'
-_SERVICE_ACCOUNT_TYPE = 'service_account'
+_AUTHORIZED_USER_TYPE = "authorized_user"
+_SERVICE_ACCOUNT_TYPE = "service_account"
_VALID_TYPES = (_AUTHORIZED_USER_TYPE, _SERVICE_ACCOUNT_TYPE)
# Help message when no credentials can be found.
@@ -42,7 +42,9 @@
explicitly create credentials and re-run the application. For more \
information, please see \
https://cloud.google.com/docs/authentication/getting-started
-""".format(env=environment_vars.CREDENTIALS).strip()
+""".format(
+ env=environment_vars.CREDENTIALS
+).strip()
# Warning when using Cloud SDK user credentials
_CLOUD_SDK_CREDENTIALS_WARNING = """\
@@ -62,6 +64,7 @@
quota. If this is the case, warn about it.
"""
from google.auth import _cloud_sdk
+
if credentials.client_id == _cloud_sdk.CLOUD_SDK_CLIENT_ID:
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
@@ -86,20 +89,21 @@
"""
if not os.path.exists(filename):
raise exceptions.DefaultCredentialsError(
- 'File {} was not found.'.format(filename))
+ "File {} was not found.".format(filename)
+ )
- with io.open(filename, 'r') as file_obj:
+ with io.open(filename, "r") as file_obj:
try:
info = json.load(file_obj)
except ValueError as caught_exc:
new_exc = exceptions.DefaultCredentialsError(
- 'File {} is not a valid json file.'.format(filename),
- caught_exc)
+ "File {} is not a valid json file.".format(filename), caught_exc
+ )
six.raise_from(new_exc, caught_exc)
# The type key should indicate that the file is either a service account
# credentials file or an authorized user credentials file.
- credential_type = info.get('type')
+ credential_type = info.get("type")
if credential_type == _AUTHORIZED_USER_TYPE:
from google.auth import _cloud_sdk
@@ -107,8 +111,7 @@
try:
credentials = _cloud_sdk.load_authorized_user_credentials(info)
except ValueError as caught_exc:
- msg = 'Failed to load authorized user credentials from {}'.format(
- filename)
+ msg = "Failed to load authorized user credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
# Authorized user credentials do not contain the project ID.
@@ -119,20 +122,20 @@
from google.oauth2 import service_account
try:
- credentials = (
- service_account.Credentials.from_service_account_info(info))
+ credentials = service_account.Credentials.from_service_account_info(info)
except ValueError as caught_exc:
- msg = 'Failed to load service account credentials from {}'.format(
- filename)
+ msg = "Failed to load service account credentials from {}".format(filename)
new_exc = exceptions.DefaultCredentialsError(msg, caught_exc)
six.raise_from(new_exc, caught_exc)
- return credentials, info.get('project_id')
+ return credentials, info.get("project_id")
else:
raise exceptions.DefaultCredentialsError(
- 'The file {file} does not have a valid type. '
- 'Type is {type}, expected one of {valid_types}.'.format(
- file=filename, type=credential_type, valid_types=_VALID_TYPES))
+ "The file {file} does not have a valid type. "
+ "Type is {type}, expected one of {valid_types}.".format(
+ file=filename, type=credential_type, valid_types=_VALID_TYPES
+ )
+ )
def _get_gcloud_sdk_credentials():
@@ -140,14 +143,12 @@
from google.auth import _cloud_sdk
# Check if application default credentials exist.
- credentials_filename = (
- _cloud_sdk.get_application_default_credentials_path())
+ credentials_filename = _cloud_sdk.get_application_default_credentials_path()
if not os.path.isfile(credentials_filename):
return None, None
- credentials, project_id = _load_credentials_from_file(
- credentials_filename)
+ credentials, project_id = _load_credentials_from_file(credentials_filename)
if not project_id:
project_id = _cloud_sdk.get_project_id()
@@ -162,7 +163,8 @@
if explicit_file is not None:
credentials, project_id = _load_credentials_from_file(
- os.environ[environment_vars.CREDENTIALS])
+ os.environ[environment_vars.CREDENTIALS]
+ )
return credentials, project_id
@@ -292,14 +294,15 @@
from google.auth.credentials import with_scopes_if_required
explicit_project_id = os.environ.get(
- environment_vars.PROJECT,
- os.environ.get(environment_vars.LEGACY_PROJECT))
+ environment_vars.PROJECT, os.environ.get(environment_vars.LEGACY_PROJECT)
+ )
checkers = (
_get_explicit_environ_credentials,
_get_gcloud_sdk_credentials,
_get_gae_credentials,
- lambda: _get_gce_credentials(request))
+ lambda: _get_gce_credentials(request),
+ )
for checker in checkers:
credentials, project_id = checker()
@@ -308,10 +311,11 @@
effective_project_id = explicit_project_id or project_id
if not effective_project_id:
_LOGGER.warning(
- 'No project ID could be determined. Consider running '
- '`gcloud config set project` or setting the %s '
- 'environment variable',
- environment_vars.PROJECT)
+ "No project ID could be determined. Consider running "
+ "`gcloud config set project` or setting the %s "
+ "environment variable",
+ environment_vars.PROJECT,
+ )
return credentials, effective_project_id
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)