google-cloud-rust
google-cloud-rust copied to clipboard
User Guide - Auth - sharing credentials
We might be better off planning all chapters of the auth user guide at once. But this is something I think we will want, and I don't want to forget it.
Consider this code:
let foo = FooClient::new();
let bar = BarClient::new();
Observation: Foo and Bar clients each have constructed a default credential, independently. They will duplicate work to get and return tokens. That is the cost of convenience in a constructor.
Where performance/efficiency matters, applications are advised to share credentials across clients. Cloned Credentials will share the caching mechanism.
let creds = create_access_token_credentials();
let foo = FooClient::new_with_config(ClientConfig::new().set_credentials(creds.clone()));
let bar = BarClient::new_with_config(ClientConfig::new().set_credentials(creds));