46 lines
1018 B
Rust

use figment::providers::{Env, Format};
use figment::{providers::Toml, Figment};
use serde::Deserialize;
use std::path::PathBuf;
pub const CONFIG_LOCATIONS: [&str; 2] = ["casket-backend/casket.toml", "/config/casket.toml"];
#[derive(Deserialize, Clone, Debug)]
pub struct Config {
pub server: Server,
pub files: Files,
pub oidc: Oidc,
pub database: Database,
}
#[derive(Deserialize, Clone, Debug)]
pub struct Server {
pub port: u16,
pub bind_address: String,
}
#[derive(Deserialize, Clone, Debug)]
pub struct Files {
pub directory: PathBuf,
}
#[derive(Deserialize, Clone, Debug)]
pub struct Oidc {
pub oidc_endpoint: String
}
#[derive(Deserialize, Clone, Debug)]
pub struct Database {
pub path: PathBuf,
}
pub fn get_config() -> figment::Result<Config> {
CONFIG_LOCATIONS
.iter()
.fold(Figment::new(), |figment, location| {
figment.merge(Toml::file(location))
})
.join(Env::prefixed("CASKET_").split("__"))
.extract()
}