1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/// Defines traits that are shared across services.
pub mod services;
/// Stores an encoded API key to be passed as a bearer token in an authorisation header.
pub struct IamAuthenticator {
apikey: String,
}
impl IamAuthenticator {
/// Encode the key and set an authorisation header template.
pub fn new<'a>(apikey: &'a str) -> Self {
let apikey = format!("apikey:{}", apikey);
let apikey = format!("Basic {}", base64::encode(apikey.as_bytes()));
Self { apikey }
}
/// Returns the authorisation header template.
pub fn apikey(&self) -> &str {
self.apikey.as_str()
}
}
