From 5f7860c748f47dff689a4b1eeff0d36edbb3f31e Mon Sep 17 00:00:00 2001 From: JesusPerez Date: Sat, 16 Oct 2021 00:29:52 +0100 Subject: [PATCH] chore: add policy and rol + checkinfo out formats --- app_env/src/appenv.rs | 115 +++++++++++++++++++++++++++++++++++++++++- app_env/src/config.rs | 12 ++--- 2 files changed, 120 insertions(+), 7 deletions(-) diff --git a/app_env/src/appenv.rs b/app_env/src/appenv.rs index b1b316a..12bc930 100644 --- a/app_env/src/appenv.rs +++ b/app_env/src/appenv.rs @@ -2,7 +2,8 @@ // Copyright 2021, Jesús Pérez Lorenzo // use std::collections::HashMap; -use serde::Deserialize; +use serde::{Serialize,Deserialize}; +use std::fmt; use crate::{ config::{Config,WebServer}, @@ -92,3 +93,115 @@ impl AppEnv { } } } + +#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum Language { + none, + en, + es, +} +impl Language { + pub fn set_provider(lang: String) -> Language { + match lang.as_str() { + "none" => Language::none, + "en" => Language::en, + "es" => Language::es, + _ => Language::none, + } + } +} +impl Default for Language { + fn default() -> Self { + Language::none + } +} +impl fmt::Display for Language { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Language::none => write!(f,"none"), + Language::en => write!(f,"en"), + Language::es => write!(f,"es"), + } + } +} +#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum Policy { + notset, + allow, + deny, + temporal, + ondemand, +} +impl Policy { + pub fn set_provider(lang: String) -> Policy { + match lang.as_str() { + "notset" => Policy::notset, + "allow" => Policy::allow, + "deny" => Policy::deny, + "temporal" => Policy::temporal, + "ondemand" => Policy::ondemand, + _ => Policy::notset, + } + } +} +impl Default for Policy { + fn default() -> Self { + Policy::notset + } +} +impl fmt::Display for Policy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Policy::notset => write!(f,"notset"), + Policy::allow => write!(f,"allow"), + Policy::deny => write!(f,"deny"), + Policy::temporal => write!(f,"temporal"), + Policy::ondemand => write!(f,"ondemand"), + } + } +} +#[derive(Eq, PartialEq, Copy, Clone, Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum Rol { + notset, + private, + public, + user, + group, + admin, + devel, +} +impl Rol { + pub fn set_provider(lang: String) -> Rol { + match lang.as_str() { + "notset" => Rol::notset, + "pivate" => Rol::private, + "public" => Rol::public, + "user" => Rol::user, + "group" => Rol::group, + "admin" => Rol::admin, + "devel" => Rol::devel, + _ => Rol::notset, + } + } +} +impl Default for Rol { + fn default() -> Self { + Rol::notset + } +} +impl fmt::Display for Rol { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Rol::notset => write!(f,"notset"), + Rol::private => write!(f,"private"), + Rol::public => write!(f,"public"), + Rol::user => write!(f,"user"), + Rol::group => write!(f,"group"), + Rol::admin => write!(f,"admin"), + Rol::devel => write!(f,"devel"), + } + } +} \ No newline at end of file diff --git a/app_env/src/config.rs b/app_env/src/config.rs index fc14999..53b14b5 100644 --- a/app_env/src/config.rs +++ b/app_env/src/config.rs @@ -84,19 +84,19 @@ impl WebServer { #[derive(Eq, PartialEq, Clone, Serialize, Debug, Deserialize)] pub enum SchedTaskStore { - None, + Notset, File(String), Acid(String), } impl Default for SchedTaskStore { fn default() -> Self { - SchedTaskStore::None + SchedTaskStore::Notset } } impl fmt::Display for SchedTaskStore { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - SchedTaskStore::None => write!(f,"none"), + SchedTaskStore::Notset => write!(f,"notset"), SchedTaskStore::File(p) => write!(f,"file: {}",p), SchedTaskStore::Acid(p) => write!(f,"acid: {}",p), } @@ -107,7 +107,7 @@ impl fmt::Display for SchedTaskStore { impl SchedTaskStore { pub fn get_value(&self) -> String { match self { - SchedTaskStore::None => format!(""), + SchedTaskStore::Notset => format!(""), SchedTaskStore::File(p) => format!("{}",p), SchedTaskStore::Acid(p) => format!("{}",p), } @@ -122,10 +122,10 @@ where D: Deserializer<'de> { Ok(match v[0] { "File" => SchedTaskStore::File(v[1].to_owned()), "Acid" => SchedTaskStore::Acid(v[1].to_owned()), - _ => SchedTaskStore::None + _ => SchedTaskStore::Notset }) } else { - Ok(SchedTaskStore::None) + Ok(SchedTaskStore::Notset) } }