gitea_pages/backend/src/config.rs

70 lines
1.6 KiB
Rust

use anyhow::{bail, Result};
use debug_ignore::DebugIgnore;
use envconfig::Envconfig;
use lazy_static::lazy_static;
use url::Url;
#[derive(Envconfig, Debug)]
pub struct Config {
#[envconfig(from = "PAGES_DB_URL")]
pub db_url: DebugIgnore<String>,
#[envconfig(from = "PAGES_AMQP_URL")]
pub amqp_url: DebugIgnore<String>,
#[envconfig(from = "PAGES_USER")]
pub user: String,
#[envconfig(from = "PAGES_PASSWORD")]
pub password: DebugIgnore<String>,
#[envconfig(from = "PAGES_GITEA_URL")]
pub gitea_url: String,
#[envconfig(from = "PAGES_GITEA_API_TOKEN")]
pub gitea_api_token: DebugIgnore<String>,
#[envconfig(from = "PAGES_GITEA_SECRET")]
pub gitea_secret: DebugIgnore<String>,
#[envconfig(from = "PAGES_GITEA_PULL_URL")]
pub gitea_pull_url: Url,
#[envconfig(from = "PAGES_GITEA_PULL_BRANCH")]
pub gitea_pull_branch: String,
#[envconfig(from = "PAGES_NGINX_CONFIG_DIR")]
pub nginx_config_dir: String,
#[envconfig(from = "PAGES_REPOS_DIR")]
pub repos_dir: String,
#[envconfig(from = "PAGES_DOMAIN")]
pub domain: String,
}
pub const PASSWORD_MIN_LEN: usize = 64;
impl Config {
pub fn validate(&self) -> Result<()> {
if self.password.len() < PASSWORD_MIN_LEN {
bail!(
"Password is too short: {} < {}",
self.password.len(),
PASSWORD_MIN_LEN
);
}
Ok(())
}
}
#[derive(Debug)]
pub struct DynConfig {
pub cloudflare_zone_name: String,
}
lazy_static! {
pub static ref CONFIG: Config = Config::init_from_env().unwrap();
}