use async_trait::async_trait;
use super::HttpError;
#[derive(Clone)]
pub enum Authorization {
Anonymous,
AAD(String),
Github(String),
Tunnel(String),
Bearer(String),
}
impl Authorization {
pub fn as_header(&self) -> Option<String> {
match self {
Authorization::AAD(token) => Some(format!("aad {}", token)),
Authorization::Github(token) => Some(format!("github {}", token)),
Authorization::Tunnel(token) => Some(format!("tunnel {}", token)),
Authorization::Bearer(token) => Some(format!("bearer {}", token)),
Authorization::Anonymous => None,
}
}
}
#[async_trait]
pub trait AuthorizationProvider: Send + Sync {
async fn get_authorization(&self) -> Result<Authorization, HttpError>;
}
pub(crate) struct StaticAuthorizationProvider(pub Authorization);
#[async_trait]
impl AuthorizationProvider for StaticAuthorizationProvider {
async fn get_authorization(&self) -> Result<Authorization, HttpError> {
Ok(self.0.clone())
}
}