Improve config system
Add pkl to generate configs
This commit is contained in:
parent
8785186dfa
commit
b2ff632e64
47 changed files with 916 additions and 277 deletions
emgauwa-controller/src
|
@ -4,7 +4,7 @@ use emgauwa_lib::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule
|
|||
use emgauwa_lib::errors::EmgauwaError;
|
||||
use emgauwa_lib::models::{Controller, FromDbModel};
|
||||
use emgauwa_lib::types::ControllerUid;
|
||||
use emgauwa_lib::utils::init_logging;
|
||||
use emgauwa_lib::utils::{drop_privileges, init_logging};
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::Sqlite;
|
||||
|
||||
|
@ -59,6 +59,9 @@ async fn create_this_relay(
|
|||
#[actix::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
let settings = settings::init()?;
|
||||
|
||||
drop_privileges(&settings.permissions)?;
|
||||
|
||||
init_logging(&settings.logging.level)?;
|
||||
|
||||
let pool = db::init(&settings.database)
|
||||
|
@ -105,7 +108,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
|
||||
let url = format!(
|
||||
"ws://{}:{}/api/v1/ws/controllers",
|
||||
settings.core.host, settings.core.port
|
||||
settings.server.host, settings.server.port
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -1,25 +1,9 @@
|
|||
use emgauwa_lib::errors::EmgauwaError;
|
||||
use emgauwa_lib::{constants, utils};
|
||||
use emgauwa_lib::settings;
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
use crate::driver::Driver;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(default)]
|
||||
#[allow(unused)]
|
||||
pub struct Core {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(default)]
|
||||
#[allow(unused)]
|
||||
pub struct Logging {
|
||||
pub level: String,
|
||||
pub file: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[serde(default)]
|
||||
#[allow(unused)]
|
||||
|
@ -35,9 +19,11 @@ pub struct Relay {
|
|||
#[serde(default)]
|
||||
#[allow(unused)]
|
||||
pub struct Settings {
|
||||
pub core: Core,
|
||||
pub server: settings::Server,
|
||||
pub database: String,
|
||||
pub logging: Logging,
|
||||
pub permissions: settings::Permissions,
|
||||
pub logging: settings::Logging,
|
||||
|
||||
pub name: String,
|
||||
pub relays: Vec<Relay>,
|
||||
}
|
||||
|
@ -45,9 +31,11 @@ pub struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Settings {
|
||||
core: Core::default(),
|
||||
database: String::from("sqlite://emgauwa-controller.sqlite"),
|
||||
logging: Logging::default(),
|
||||
server: settings::Server::default(),
|
||||
database: String::from("sqlite://_local/emgauwa-controller.sqlite"),
|
||||
permissions: settings::Permissions::default(),
|
||||
logging: settings::Logging::default(),
|
||||
|
||||
name: String::from("Emgauwa Controller"),
|
||||
relays: Vec::new(),
|
||||
}
|
||||
|
@ -66,26 +54,8 @@ impl Default for Relay {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Core {
|
||||
fn default() -> Self {
|
||||
Core {
|
||||
host: String::from("127.0.0.1"),
|
||||
port: constants::DEFAULT_PORT,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Logging {
|
||||
fn default() -> Self {
|
||||
Logging {
|
||||
level: String::from("info"),
|
||||
file: String::from("stdout"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() -> Result<Settings, EmgauwaError> {
|
||||
let mut settings: Settings = utils::load_settings("controller", "CONTROLLER")?;
|
||||
let mut settings: Settings = settings::load("controller", "CONTROLLER")?;
|
||||
|
||||
for (num, relay) in settings.relays.iter_mut().enumerate() {
|
||||
if relay.number.is_none() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue