pub struct Token { /* private fields */ }
Expand description
Represents an access token that can be used as a bearer token in HTTP requests
Tokens should not be cached, the AuthenticationManager
handles the correct caching
already.
The token does not implement Display
to avoid accidentally printing the token in log
files, likewise Debug
does not expose the token value itself which is only available
using the Token::as_str
method.
Token data as returned by the server
https://cloud.google.com/iam/docs/reference/sts/rest/v1/TopLevel/token#response-body
Implementations§
source§impl Token
impl Token
sourcepub fn has_expired(&self) -> bool
pub fn has_expired(&self) -> bool
Define if the token has has_expired
This takes an additional 30s margin to ensure the token can still be reasonably used instead of expiring right after having checked.
Note: The official Python implementation uses 20s and states it should be no more than 30s. The official Go implementation uses 10s (0s for the metadata server). The docs state, the metadata server caches tokens until 5 minutes before expiry. We use 20s to be on the safe side.
sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
Get expiry of token, if available
Trait Implementations§
source§impl<'de> Deserialize<'de> for Token
impl<'de> Deserialize<'de> for Token
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)