pub struct Builder { /* private fields */ }Expand description
Creates Credentials instances backed by the Metadata Service.
While the Google Cloud client libraries for Rust default to credentials backed by the metadata service, some applications may need to:
- Customize the metadata service credentials in some way
- Bypass the Application Default Credentials lookup and only use the metadata server credentials
- Use the credentials directly outside the client libraries
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn with_endpoint<S: Into<String>>(self, endpoint: S) -> Self
pub fn with_endpoint<S: Into<String>>(self, endpoint: S) -> Self
Sets the endpoint for this credentials.
A trailing slash is significant, so specify the base URL without a trailing
slash. If not set, the credentials use http://metadata.google.internal.
§Example
let credentials = Builder::default()
.with_endpoint("https://metadata.google.foobar")
.build();Sourcepub fn with_quota_project_id<S: Into<String>>(self, quota_project_id: S) -> Self
pub fn with_quota_project_id<S: Into<String>>(self, quota_project_id: S) -> Self
Set the quota project for this credentials.
In some services, you can use a service account in
one project for authentication and authorization, and charge
the usage to a different project. This may require that the
service account has serviceusage.services.use permissions on the quota project.
Sourcepub fn with_scopes<I, S>(self, scopes: I) -> Self
pub fn with_scopes<I, S>(self, scopes: I) -> Self
Sets the scopes for this credentials.
Metadata server issues tokens based on the requested scopes. If no scopes are specified, the credentials defaults to all scopes configured for the default service account on the instance.
Sourcepub fn with_retry_policy<V: Into<RetryPolicyArg>>(self, v: V) -> Self
pub fn with_retry_policy<V: Into<RetryPolicyArg>>(self, v: V) -> Self
Configure the retry policy for fetching tokens.
The retry policy controls how to handle retries, and sets limits on the number of attempts or the total time spent retrying.
use gax::retry_policy::{AlwaysRetry, RetryPolicyExt};
let credentials = Builder::default()
.with_retry_policy(AlwaysRetry.with_attempt_limit(3))
.build();Sourcepub fn with_backoff_policy<V: Into<BackoffPolicyArg>>(self, v: V) -> Self
pub fn with_backoff_policy<V: Into<BackoffPolicyArg>>(self, v: V) -> Self
Configure the retry backoff policy.
The backoff policy controls how long to wait in between retry attempts.
use gax::exponential_backoff::ExponentialBackoff;
let policy = ExponentialBackoff::default();
let credentials = Builder::default()
.with_backoff_policy(policy)
.build();Sourcepub fn with_retry_throttler<V: Into<RetryThrottlerArg>>(self, v: V) -> Self
pub fn with_retry_throttler<V: Into<RetryThrottlerArg>>(self, v: V) -> Self
Configure the retry throttler.
Advanced applications may want to configure a retry throttler to Address Cascading Failures and when Handling Overload conditions. The authentication library throttles its retry loop, using a policy to control the throttling algorithm. Use this method to fine tune or customize the default retry throttler.
use gax::retry_throttler::AdaptiveThrottler;
let credentials = Builder::default()
.with_retry_throttler(AdaptiveThrottler::default())
.build();Sourcepub fn build(self) -> Result<Credentials, Error>
pub fn build(self) -> Result<Credentials, Error>
Returns a Credentials instance with the configured settings.
Sourcepub fn build_access_token_credentials(
self,
) -> Result<AccessTokenCredentials, Error>
pub fn build_access_token_credentials( self, ) -> Result<AccessTokenCredentials, Error>
Returns an AccessTokenCredentials instance with the configured settings.
§Example
let credentials: AccessTokenCredentials = Builder::default()
.with_quota_project_id("my-quota-project")
.build_access_token_credentials()?;
let access_token = credentials.access_token().await?;
println!("Token: {}", access_token.token);