2021-03-20 02:31:41 +00:00
|
|
|
#![feature(proc_macro_hygiene, decl_macro)]
|
|
|
|
|
|
|
|
#[macro_use] extern crate rocket;
|
2021-03-26 22:30:38 +00:00
|
|
|
#[macro_use] extern crate diesel;
|
|
|
|
|
2021-03-20 18:18:08 +00:00
|
|
|
mod models;
|
2021-03-20 02:31:41 +00:00
|
|
|
mod config;
|
2021-03-26 22:30:38 +00:00
|
|
|
mod schema;
|
2021-04-02 20:09:51 +00:00
|
|
|
mod routes;
|
2022-03-04 12:08:03 +00:00
|
|
|
mod dns;
|
2021-03-20 02:31:41 +00:00
|
|
|
|
2022-04-22 22:27:16 +00:00
|
|
|
use std::process::exit;
|
|
|
|
|
|
|
|
use figment::{Figment, Profile, providers::{Format, Toml, Env}};
|
2022-04-22 23:34:04 +00:00
|
|
|
use rocket_sync_db_pools::database;
|
|
|
|
use clap::{Parser, Subcommand};
|
2022-04-22 22:27:16 +00:00
|
|
|
|
2021-04-02 20:09:51 +00:00
|
|
|
use routes::users::*;
|
|
|
|
use routes::zones::*;
|
2021-03-20 18:18:08 +00:00
|
|
|
|
2022-04-22 22:27:16 +00:00
|
|
|
|
|
|
|
#[database("sqlite")]
|
2021-03-26 22:30:38 +00:00
|
|
|
pub struct DbConn(diesel::SqliteConnection);
|
2021-03-20 02:31:41 +00:00
|
|
|
|
2022-04-22 23:34:04 +00:00
|
|
|
#[derive(Parser)]
|
|
|
|
#[clap(author, version, about, long_about = None)]
|
|
|
|
#[clap(propagate_version = true)]
|
|
|
|
struct Nomilo {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
command: Command
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand)]
|
|
|
|
enum Command {
|
|
|
|
/// Lauch web server
|
|
|
|
Serve,
|
|
|
|
}
|
|
|
|
|
2022-04-22 22:27:16 +00:00
|
|
|
|
2022-04-22 23:34:04 +00:00
|
|
|
fn serve(figment: Figment, app_config: config::Config) {
|
|
|
|
rocket::async_main(async move {
|
|
|
|
let _res = rocket::custom(figment)
|
|
|
|
.manage(app_config)
|
|
|
|
.attach(DbConn::fairing())
|
|
|
|
.mount("/api/v1", routes![
|
|
|
|
get_zone_records,
|
|
|
|
create_zone_records,
|
|
|
|
update_zone_records,
|
|
|
|
delete_zone_records,
|
|
|
|
get_zones,
|
|
|
|
create_zone,
|
|
|
|
add_member_to_zone,
|
|
|
|
create_auth_token,
|
|
|
|
create_user,
|
|
|
|
])
|
|
|
|
.launch().await;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
2022-04-22 22:27:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2021-03-20 02:31:41 +00:00
|
|
|
|
2022-04-22 23:34:04 +00:00
|
|
|
let nomilo = Nomilo::parse();
|
|
|
|
|
|
|
|
match nomilo.command {
|
|
|
|
Command::Serve => serve(figment, app_config),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-20 02:31:41 +00:00
|
|
|
}
|