52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
use config::{Config, ConfigError};
|
|
use tracing::warn;
|
|
|
|
use crate::configs::key::{
|
|
AUTH_DEFAULT_ADMIN_PASSWORD_KEY, AUTH_DEFAULT_ADMIN_USERNAME_KEY, AUTH_JWT_SECRET_KEY,
|
|
};
|
|
|
|
use super::FromConfig;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct AuthSettings {
|
|
pub jwt_secret: Option<String>,
|
|
pub default_admin_username: Option<String>,
|
|
pub default_admin_password: Option<String>,
|
|
}
|
|
|
|
impl FromConfig for AuthSettings {
|
|
fn from_config(_config: &Config) -> Result<Self, String> {
|
|
Ok(AuthSettings {
|
|
jwt_secret: _config
|
|
.get_string(AUTH_JWT_SECRET_KEY)
|
|
.inspect_err(|err| {
|
|
match err {
|
|
ConfigError::NotFound(_) => {
|
|
warn!(
|
|
"{} not found in configuration, A random secret will be generated at runtime.",
|
|
AUTH_JWT_SECRET_KEY
|
|
);
|
|
}
|
|
_ => {
|
|
warn!(
|
|
"Failed to read {} from configuration, A random secret will be generated at runtime: {}",
|
|
AUTH_JWT_SECRET_KEY, err
|
|
);
|
|
}
|
|
};
|
|
})
|
|
.ok(),
|
|
default_admin_username: _config
|
|
.get_string(AUTH_DEFAULT_ADMIN_USERNAME_KEY)
|
|
.ok(),
|
|
default_admin_password: _config
|
|
.get_string(AUTH_DEFAULT_ADMIN_PASSWORD_KEY)
|
|
.ok(),
|
|
})
|
|
}
|
|
|
|
fn validate(&self) -> Result<(), String> {
|
|
Ok(())
|
|
}
|
|
}
|