google-apis-rs / google-cloud-rs

Asynchronous Rust bindings for Google Cloud Platform APIs.
176 stars 48 forks source link

Rename `new()` to `from_application_default_credentials()` #15

Open mwilliammyers opened 4 years ago

mwilliammyers commented 4 years ago

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 commented 4 years ago

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

Hirevo commented 4 years ago

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 commented 3 years ago

https://github.com/google-apis-rs/google-cloud-rs/blob/e3569046fd571469f058e045bb6c3a8ba241fd73/google-cloud/src/datastore/client.rs#L50-L52

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.