Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rename new() to from_application_default_credentials() #15

Open
mwilliammyers opened this issue May 30, 2020 · 3 comments
Open

Rename new() to from_application_default_credentials() #15

mwilliammyers opened this issue May 30, 2020 · 3 comments
Assignees
Labels
C-question Category: Question C-refactor Category: Refactorings

Comments

@mwilliammyers
Copy link
Member

mwilliammyers commented May 30, 2020

What do you think about renaming new() to from_application_default_credentials()? I was a little surprised when I found out that new depended on the GOOGLE_APPLICATION_CREDENTIALS env var being set. I also think it mirrors from_credentials nicely.

This would also set us up to implement the entire Application Default Credentials (ADC) flow in the future. This would require us querying metadata servers (on GCE or App Engine etc) to get credentials if the GOOGLE_APPLICATION_CREDENTIALS env var is not found.

@mwilliammyers mwilliammyers self-assigned this May 30, 2020
@mwilliammyers mwilliammyers added C-question Category: Question C-refactor Category: Refactorings labels May 30, 2020
@mwilliammyers
Copy link
Member Author

I wonder if we should rename from_credentials to with_credentials and make it with_application_default_credentials...

@Hirevo
Copy link
Member

Hirevo commented Jun 2, 2020

I don't really know what's best here.
According to this page from the official docs, the different official client libraries all do it in a slightly different way.

I picked Client::new() because of Golang's client, who does it like this:

// equivalent to our `Client::new()`
storage.NewClient(ctx)

// equivalent to our `Client::from_credentials(creds)`
storage.NewClient(ctx, option.WithCredentials(creds))

Maybe completing ADC can be done by extending/changing ApplicationCredentials ?
I don't know because I never used GCE nor App Engine.

@FranklinYu
Copy link

let path = env::var("GOOGLE_APPLICATION_CREDENTIALS")?;
let file = File::open(path)?;
let creds = json::from_reader(file)?;

Currently these 3 lines are in all clients. How about extracting it to a function in the authorize module? Then if we want to support ADC in future, we only update one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: Question C-refactor Category: Refactorings
Projects
None yet
Development

No branches or pull requests

3 participants