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
pub mod emulator;
pub mod error;
pub mod gcp;
use async_trait::async_trait;
use error::CredentialsError;
use error_stack::{IntoReport, Report, ResultExt};
use headers::{authorization::Bearer, Authorization, HeaderMapExt};
use http::header::HeaderMap;
#[async_trait]
pub trait Credentials {
async fn get_access_token(&self, scopes: &[&str]) -> Result<String, Report<CredentialsError>>;
async fn set_credentials(
&self,
headers: &mut HeaderMap,
scopes: &[&str],
) -> Result<(), Report<CredentialsError>> {
let token = self.get_access_token(scopes).await?;
headers.typed_insert(
Authorization::<Bearer>::bearer(&token)
.into_report()
.change_context(CredentialsError::InvalidAccessToken)?,
);
Ok(())
}
}