From e656f5eec1bc8cd19a9dd6313659c3d8c2a26ea0 Mon Sep 17 00:00:00 2001 From: Avril Date: Sun, 2 Aug 2020 01:08:08 +0100 Subject: [PATCH] reorganise --- src/config/error.rs | 17 ++++++++++++ src/config/global.rs | 21 +++++++++++++++ src/{config.rs => config/job.rs} | 46 +++++++++----------------------- src/config/mod.rs | 28 +++++++++++++++++++ src/config/parse.rs | 8 ++++++ src/context.rs | 1 - src/live.rs | 2 +- src/main.rs | 5 ++-- 8 files changed, 90 insertions(+), 38 deletions(-) create mode 100644 src/config/error.rs create mode 100644 src/config/global.rs rename src/{config.rs => config/job.rs} (70%) create mode 100644 src/config/mod.rs create mode 100644 src/config/parse.rs diff --git a/src/config/error.rs b/src/config/error.rs new file mode 100644 index 0000000..8132abf --- /dev/null +++ b/src/config/error.rs @@ -0,0 +1,17 @@ +//! Config parsing error + +use super::*; + +#[derive(Debug)] +pub enum Error { + +} + +impl std::error::Error for Error{} +impl std::fmt::Display for Error +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result + { + todo!() + } +} diff --git a/src/config/global.rs b/src/config/global.rs new file mode 100644 index 0000000..498d6da --- /dev/null +++ b/src/config/global.rs @@ -0,0 +1,21 @@ +//! Global config stuff +use super::*; + +/// Global user config +#[derive(Debug)] +pub struct Config +{ + /// The directories to find jobs in + pub job_dirs: Vec, + /// The rules for users + pub user_rules: Vec, +} + +impl Default for Config +{ + #[inline] + fn default() -> Self + { + Self{job_dirs: Vec::new(), user_rules: Vec::new()} + } +} diff --git a/src/config.rs b/src/config/job.rs similarity index 70% rename from src/config.rs rename to src/config/job.rs index 79c53b9..1ee4375 100644 --- a/src/config.rs +++ b/src/config/job.rs @@ -1,12 +1,5 @@ +//! Job config use super::*; -use std::{ - str, - fmt, - path::{ - PathBuf, - }, -}; - /// Target for oneshots #[derive(Debug,Eq,PartialEq,Hash)] @@ -47,6 +40,8 @@ pub struct Job what: Command, } +// Global config + /// Type of access #[derive(Debug, PartialEq,Eq,Hash)] pub enum Access @@ -55,37 +50,20 @@ pub enum Access Deny, } +/// A permission entry for users +#[derive(Debug,PartialEq,Eq,Hash)] +pub enum UserPermAlias { + Single(String), + Group(String), + All, +} + /// Access rule for user #[derive(Debug, PartialEq,Eq,Hash)] pub struct UserRule { - user: String, + user: UserPermAlias, mode: Access, } const DEFAULT_JOB_DIR: &str = "/etc/rori.kron"; - -/// User config -#[derive(Debug)] -pub struct Config -{ - pub job_dirs: Vec, - pub user_rules: Vec, - -} - -#[derive(Debug)] -pub enum Error { - -} -impl std::error::Error for Error{} -impl std::fmt::Display for Error -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result - { - todo!() - } -} - - - diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 0000000..4891478 --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1,28 @@ +use super::*; +use std::{ + str, + fmt, + path::{ + PathBuf, + Path, + }, +}; + +mod parse; +mod error; +pub use error::*; + +mod job; +pub use job::*; + +mod global; +pub use global::*; + +/// Parse a single config file +#[inline] +pub fn parse_global_single(path: impl AsRef) -> Result +{ + let mut cfg = Config::default(); + parse::global(&mut cfg, path)?; + Ok(cfg) +} diff --git a/src/config/parse.rs b/src/config/parse.rs new file mode 100644 index 0000000..5b7c9ab --- /dev/null +++ b/src/config/parse.rs @@ -0,0 +1,8 @@ +//! Parses the config files +use super::*; + +/// Parse a single config file +pub fn global(to: &mut Config, path: impl AsRef) -> Result<(), error::Error> +{ + todo!() +} diff --git a/src/context.rs b/src/context.rs index ef24152..e1b0fd7 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,5 +1,4 @@ //! Context that is passed to all workers and children - use super::*; use std::sync::{Arc, Weak}; diff --git a/src/live.rs b/src/live.rs index 30257f3..5978163 100644 --- a/src/live.rs +++ b/src/live.rs @@ -23,6 +23,6 @@ pub struct Oneesan { /// Start watching this path for changes of files pub fn watch(path: PathBuf) -> Oneesan { - + todo!() } diff --git a/src/main.rs b/src/main.rs index 8a37933..360edd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,9 @@ mod log; mod interval; mod config; -//mod context; -//mod live; +mod live; +mod context; +mod job; async fn do_thing_every() -> Result<(mpsc::Sender<()>, task::JoinHandle<()>), Box> {