pub struct GoogleAccessToken { /* private fields */ }Expand description
A cached source of Google OAuth2 access tokens. See the module docs.
Implementations§
Source§impl GoogleAccessToken
impl GoogleAccessToken
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
GOOGLE_ACCESS_TOKEN when set; otherwise the metadata server when one
answers (Cloud Run, GKE, Compute Engine), else gcloud auth print-access-token. GCE_METADATA_HOST overrides the metadata host.
Sourcepub fn metadata_server(host: impl Into<String>) -> Self
pub fn metadata_server(host: impl Into<String>) -> Self
Tokens for the attached service account, from the metadata server at
host (normally metadata.google.internal).
Sourcepub async fn token(&self) -> Result<String, AuthError>
pub async fn token(&self) -> Result<String, AuthError>
A valid access token, fetching a new one when the cached one is about to expire.
Sourcepub async fn invalidate(&self)
pub async fn invalidate(&self)
Forget the cached token, e.g. after a request was rejected with 401.
Sourcepub async fn into_access_token(self) -> Result<AccessToken, AuthError>
pub async fn into_access_token(self) -> Result<AccessToken, AuthError>
An AccessToken that stays valid for as long as it is held.
AccessToken is read synchronously on every connection attempt,
and fetching a token is asynchronous, so the token is fetched here
once (an error means there are no usable credentials) and then kept
fresh by a background task. The task checks every minute and fetches
a new token shortly before the current one expires. It stops once
every clone of the returned AccessToken is dropped. If a refresh
fails, the previous token is kept and the next check retries.
Must be called inside a Tokio runtime.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GoogleAccessToken
impl !RefUnwindSafe for GoogleAccessToken
impl Send for GoogleAccessToken
impl Sync for GoogleAccessToken
impl Unpin for GoogleAccessToken
impl !UnwindSafe for GoogleAccessToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].