unify rocket and nomilo config files
This commit is contained in:
parent
a839bc25cf
commit
d75e3704e4
7 changed files with 34 additions and 18 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,6 +1,6 @@
|
|||
/target
|
||||
|
||||
config.toml
|
||||
nomilo.toml
|
||||
db.sqlite
|
||||
__pycache__
|
||||
/env
|
||||
/env
|
||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -914,6 +914,7 @@ dependencies = [
|
|||
"diesel",
|
||||
"diesel-derive-enum",
|
||||
"djangohashers",
|
||||
"figment",
|
||||
"humantime",
|
||||
"jsonwebtoken",
|
||||
"rocket",
|
||||
|
|
|
@ -23,3 +23,4 @@ jsonwebtoken = "7.2.0"
|
|||
chrono = { version = "0.4", features = ["serde"] }
|
||||
humantime = "2.1.0"
|
||||
tokio = "1"
|
||||
figment = { version = "0.10.6", features = ["toml", "env"] }
|
|
@ -1,2 +0,0 @@
|
|||
[global.databases]
|
||||
db = { url = "db.sqlite" }
|
|
@ -1,7 +1,10 @@
|
|||
[web_app]
|
||||
[global.databases.sqlite]
|
||||
url = "db.sqlite"
|
||||
|
||||
[release.web_app]
|
||||
# base64 secret, change it (openssl rand -base64 32)
|
||||
secret = "Y2hhbmdlbWUK"
|
||||
token_duration = "1d"
|
||||
|
||||
[dns]
|
||||
[release.dns]
|
||||
server = "127.0.0.1:53"
|
|
@ -1,6 +1,4 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use chrono::Duration;
|
||||
|
@ -39,11 +37,6 @@ fn from_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
|||
.and_then(|duration| Duration::from_std(duration).map_err(|err| Error::custom(err.to_string())))
|
||||
}
|
||||
|
||||
pub fn load(file_name: PathBuf) -> Config {
|
||||
let file_content = fs::read_to_string(file_name).expect("could not read config file");
|
||||
toml::from_str(&file_content).expect("could not parse config file")
|
||||
}
|
||||
|
||||
// TODO: Maybe remove this
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for DnsClient {
|
||||
|
@ -60,7 +53,6 @@ impl<'r> FromRequest<'r> for DnsClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for Box<dyn RecordConnector> {
|
||||
type Error = ();
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -9,20 +9,41 @@ mod schema;
|
|||
mod routes;
|
||||
mod dns;
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
use figment::{Figment, Profile, providers::{Format, Toml, Env}};
|
||||
|
||||
use routes::users::*;
|
||||
use routes::zones::*;
|
||||
use rocket_sync_db_pools::database;
|
||||
|
||||
|
||||
#[database("db")]
|
||||
|
||||
#[database("sqlite")]
|
||||
pub struct DbConn(diesel::SqliteConnection);
|
||||
|
||||
|
||||
#[launch]
|
||||
async fn rocket() -> _ {
|
||||
let app_config = config::load("config.toml".into());
|
||||
println!("{:#?}", app_config);
|
||||
//let app_config = config::load("config.toml".into());
|
||||
//println!("{:#?}", app_config);
|
||||
|
||||
rocket::build()
|
||||
|
||||
let figment = Figment::from(rocket::Config::default())
|
||||
.merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested())
|
||||
.merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global())
|
||||
.select(Profile::from_env_or("NOMILO_PROFILE", "release"));
|
||||
|
||||
let app_config = match figment.extract::<config::Config>() {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
eprintln!("Error loading configuration: {}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
//let app_config = .expect("unable to load configuration");
|
||||
|
||||
rocket::custom(figment)
|
||||
.manage(app_config)
|
||||
.attach(DbConn::fairing())
|
||||
.mount("/api/v1", routes![
|
||||
|
|
Loading…
Reference in a new issue