1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::sync::Arc;
use chrono::{DateTime, Utc};
#[cfg(any(test, feature = "oauth-token-provider"))]
pub mod oauth;
mod renewing;
pub use renewing::RenewingTokenProvider;
#[cfg_attr(any(test, feature = "mocks"), mockall::automock)]
#[async_trait::async_trait]
pub trait TokenProvider: Send + Sync {
async fn get_token(&self) -> anyhow::Result<Arc<Token>>;
}
#[derive(Clone)]
#[cfg_attr(test, derive(Debug, PartialEq, Eq))]
pub struct Token {
pub token: String,
pub expiry: DateTime<Utc>,
}
impl Default for Token {
fn default() -> Self {
Self {
token: Default::default(),
expiry: DateTime::from_utc(chrono::NaiveDateTime::from_timestamp(0, 0), Utc),
}
}
}
impl AsRef<str> for Token {
fn as_ref(&self) -> &str {
&self.token
}
}