Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: make load_credentials_from_file a public method #530

Merged
merged 10 commits into from
Jun 18, 2020

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Jun 12, 2020

Turns _load_credentials_from_file into a public method load_credentials_from_file. Also allow scopes to be passed.

import google.auth

credentials, project_id = google.auth.load_credentials_from_file(
    "path/to/credentials.json",
    scopes=["https://www.google.com/calendar/feeds"]
)

On second thought, I'm not sure exposing this method this way is appropriate. Might be deceptive given that it isn't a magical method that can load all credentials 🤔

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 12, 2020
@busunkim96 busunkim96 requested a review from software-dov June 12, 2020 02:15
@busunkim96 busunkim96 requested a review from crwilcox June 15, 2020 20:21
google/auth/_default.py Outdated Show resolved Hide resolved
Comment on lines 140 to 145
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
)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The control flow is a little tricky to eyeball grep. It may be easier if it were changed to be something like

if credential_type is None:
    raise exceptions.DefaultCredentialsError(...)
# dedented control flow

@busunkim96 busunkim96 requested a review from software-dov June 16, 2020 19:53
@arithmetic1728
Copy link
Contributor

@busunkim96 This happens to be exactly what I need for my gcloud auth file override work (where gcloud reads cred json files to create google-auth creds)

@arithmetic1728 arithmetic1728 self-requested a review June 17, 2020 22:18
@arithmetic1728
Copy link
Contributor

@software-dov Please take another look, thanks!

@arithmetic1728 arithmetic1728 merged commit 15d5fa9 into master Jun 18, 2020
@arithmetic1728 arithmetic1728 deleted the support-scopes branch June 18, 2020 21:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants