Add more functionality to the global config parser

Still need to add user permissions.
master
not manx 4 years ago
parent a0fc94d960
commit ee355f088a
Signed by: C-xC-c
GPG Key ID: F52ED472284EF2F4

@ -0,0 +1,7 @@
((jobs-dir "/etc/rori.kron")
(debug t)
(allow
:all)
(deny
(:user "flon")
(:uid 8008)))

@ -21,8 +21,8 @@ pub enum UserPermAlias {
#[derive(Debug, PartialEq,Eq,Hash)] #[derive(Debug, PartialEq,Eq,Hash)]
pub struct UserRule pub struct UserRule
{ {
user: UserPermAlias, pub user: UserPermAlias,
mode: Access, pub mode: Access,
} }
/// Global user config /// Global user config

@ -17,14 +17,36 @@ fn get_atom_string<'a>(maybe_atom: &'a Sexp) -> Result<&'a String, Error>
} }
} }
fn new_job(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> { #[inline]
let what = &cdr[0]; fn add_job(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> {
let what = get_atom_string(what)?; to.job_dirs.push(PathBuf::from(get_atom_string(&cdr[0])?));
to.job_dirs.push(PathBuf::from(what));
Ok(()) Ok(())
} }
#[inline]
fn set_debug(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> {
if !to.debug {
let debug = get_atom_string(&cdr[0])?;
to.debug = match debug.to_lowercase().trim() {
"t" => true,
"nil" => false,
_ => return Err(Error::Unknown)
};
} else {
// Should be debug is set.
return Err(Error::Unknown)
}
Ok(())
}
#[inline]
fn mwee(to: &mut Config, cdr: &[Sexp]) -> Result<(), Error> {
println!("{:?}", cdr);
Ok(())
}
/// Parse a single config file /// Parse a single config file
pub async fn global(to: &mut Config, path: impl AsRef<Path>) -> Result<(), error::Error> pub async fn global(to: &mut Config, path: impl AsRef<Path>) -> Result<(), error::Error>
{ {
@ -48,10 +70,10 @@ pub async fn global(to: &mut Config, path: impl AsRef<Path>) -> Result<(), error
Sexp::Atom(car) => { Sexp::Atom(car) => {
if let Atom::S(car) = car { if let Atom::S(car) = car {
match car.to_lowercase().trim() { match car.to_lowercase().trim() {
"jobs-dir" => new_job(to, cdr), "jobs-dir" => add_job(to, cdr),
"debug" => new_job(to, cdr), "debug" => set_debug(to ,cdr),
"allow" => new_job(to, cdr), "allow" => mwee(to, cdr),
"deny" => new_job(to, cdr), "deny" => mwee(to, cdr),
_ => return Err(Error::Unknown), _ => return Err(Error::Unknown),
}?; }?;
} else { } else {

Loading…
Cancel
Save