Skip to content

Commit 879fd84

Browse files
committed
feat: Introduce validators for load_from_* methods
1 parent c3ea09f commit 879fd84

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

google/auth/_default.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from google.auth import environment_vars
2727
from google.auth import exceptions
28+
from google.auth import constraints
2829
import google.auth.transport._http_client
2930

3031
_LOGGER = logging.getLogger(__name__)
@@ -127,9 +128,13 @@ def load_credentials_from_file(
127128
filename, info, scopes, default_scopes, quota_project_id, request
128129
)
129130

130-
131131
def load_credentials_from_dict(
132132
info, scopes=None, default_scopes=None, quota_project_id=None, request=None
133+
):
134+
return load_credentials_from_dict_with_constraints(info, constraints.Constraints(allow_types="all"), scopes, default_scopes, quota_project_id, request)
135+
136+
def load_credentials_from_dict_with_constraints(
137+
info, constraints, scopes=None, default_scopes=None, quota_project_id=None, request=None
133138
):
134139
"""Loads Google credentials from a dict.
135140
@@ -173,12 +178,15 @@ def load_credentials_from_dict(
173178

174179

175180
def _load_credentials_from_info(
176-
filename, info, scopes, default_scopes, quota_project_id, request
181+
filename, info, scopes, default_scopes, quota_project_id, request, constraints
177182
):
178183
from google.auth.credentials import CredentialsWithQuotaProject
179184

180185
credential_type = info.get("type")
181186

187+
if constraints.isValid(info) is False:
188+
raise exceptions.InvalidType(f"{credential_type} is not allowed as per provided constraints or is not a valid credential type")
189+
182190
if credential_type == _AUTHORIZED_USER_TYPE:
183191
credentials, project_id = _get_authorized_user_credentials(
184192
filename, info, scopes

0 commit comments

Comments
 (0)