use base64::prelude::*;
use serde::Deserialize;
#[doc(hidden)]
fn default_username() -> String {
"admin".to_string()
}
#[doc(hidden)]
fn default_password() -> String {
"password".to_string()
}
#[doc(hidden)]
const fn default_enabled() -> bool {
true
}
#[derive(Deserialize, Clone, Debug)]
pub struct Auth {
#[serde(default = "default_enabled")]
pub enabled: bool,
#[serde(default = "default_username")]
pub username: String,
#[serde(default = "default_password")]
pub password: String,
}
impl Default for Auth {
fn default() -> Self {
Self {
enabled: default_enabled(),
username: default_username(),
password: default_password(),
}
}
}
impl Auth {
pub fn to_auth_encoded(&self) -> String {
format!(
"Basic {}",
BASE64_STANDARD.encode(format!("{}:{}", self.username, self.password))
)
}
}