chore: change verbose to isize, only println if verbose > 0 (env WEB_SERVER_VERBOSE)

This commit is contained in:
Jesús Pérez Lorenzo 2021-09-17 17:07:26 +01:00
parent b5685bbe40
commit ad0664c90b
5 changed files with 26 additions and 18 deletions

View File

@ -97,10 +97,10 @@ pub struct AuthStore {
impl AuthStore {
#[must_use]
pub fn new(config: &WebServer, enforcer: SharedEnforcer,verbose: &str) -> Self {
pub fn new(config: &WebServer, enforcer: SharedEnforcer,verbose: isize) -> Self {
Self {
users: Arc::new(RwLock::new(AuthStore::create_user_map(config,&verbose))),
shadows: Arc::new(RwLock::new(AuthStore::create_shadows_map(config,&verbose))),
users: Arc::new(RwLock::new(AuthStore::create_user_map(config,verbose))),
shadows: Arc::new(RwLock::new(AuthStore::create_shadows_map(config,verbose))),
sessions: Arc::new(RwLock::new(HashMap::new())),
enforcer,
}
@ -136,13 +136,13 @@ impl AuthStore {
shadows
}
#[must_use]
pub fn create_user_map(config: &WebServer,verbose: &str) -> HashMap<String, User> {
pub fn create_user_map(config: &WebServer,verbose: isize) -> HashMap<String, User> {
// TODO load form YAML o CONFIG
let mut usrs = HashMap::new();
match config.usrs_store.as_str() {
"fs" => {
usrs = AuthStore::load_users_from_fs(&config.usrs_store,&config.usrs_store_target);
if !usrs.is_empty() && verbose != "quiet" {
if !usrs.is_empty() && verbose > 0 {
println!("Users loaded successfully ({})", &usrs.len());
}
},
@ -151,13 +151,13 @@ impl AuthStore {
usrs
}
#[must_use]
pub fn create_shadows_map(config: &WebServer,verbose: &str) -> HashMap<String, UserShadow> {
pub fn create_shadows_map(config: &WebServer,verbose: isize) -> HashMap<String, UserShadow> {
// TODO load form YAML o CONFIG
let mut shadows = HashMap::new();
match config.usrs_shadow_store.as_str() {
"fs" => {
shadows = AuthStore::load_shadows_from_fs(&config.usrs_shadow_store,&config.usrs_shadow_target);
if !shadows.is_empty() && verbose != "quiet" {
if !shadows.is_empty() && verbose > 0 {
println!("Users info successfully ({})",&shadows.len());
}
},

View File

@ -29,7 +29,7 @@ pub struct AppData {
impl AppData {
/// Schema creation for `AppEnv`
#[must_use]
pub fn new(env: AppEnv) -> Self {
pub fn new(env: AppEnv, verbose: isize) -> Self {
let config = env.get_curr_websrvr_config();
let templates_path = config.templates_path.to_owned();
let default_module = config.default_module.to_owned();
@ -40,7 +40,9 @@ impl AppData {
let templates = format!("{}/**/*", &templates_path);
tera = match tera::Tera::new(templates.as_str()) {
Ok(t) => {
println!("WebServices Templates loaded from: {}", &templates_path);
if verbose > 0 {
println!("WebServices Templates loaded from: {}", &templates_path);
}
t
}
Err(e) => {
@ -58,7 +60,9 @@ impl AppData {
for (key, value) in &data_hash { //.iter() {
ctx.insert(key, value);
}
println!("Default WebServices templates module loaded from: {}", &data_path);
if verbose > 0 {
println!("Default WebServices templates module loaded from: {}", &data_path);
}
}
Err(e) => {
println!("Error parsing data {}:{}", &data_path, e);

View File

@ -213,14 +213,14 @@ pub struct Config {
}
impl Config {
pub fn load_file_content(verbose: &str, cfg_path: &str) -> String {
pub fn load_file_content(verbose: isize, cfg_path: &str) -> String {
let config_path: String;
if cfg_path.is_empty() {
config_path = envmnt::get_or("APP_CONFIG_PATH", "config.toml");
} else {
config_path = cfg_path.to_string();
}
if verbose != "quiet" {
if verbose > 0 {
println!("Config path: {}", &config_path);
}
std::fs::read_to_string(&config_path)
@ -229,10 +229,10 @@ impl Config {
String::from("")
})
}
pub fn new(content: String,verbose: &str) -> Self {
pub fn new(content: String,verbose: isize) -> Self {
match toml::from_str(&content) {
Ok(cfg) => {
if verbose != "quiet" {
if verbose > 0 {
println!("Config Loaded successfully");
}
let app_home=envmnt::get_or("APP_HOME", ".");

View File

@ -47,12 +47,14 @@ impl Module {
String::from("")
})
}
pub fn new(content: String) -> Self {
pub fn new(content: String, verbose: isize) -> Self {
// let modul_def: toml::Value = toml::from_str(&content)?;
// if let Some(name) = modul_def["name"].as_str() {
match toml::from_str(&content) {
Ok(cfg) => {
println!("Module Loaded successfully");
if verbose > 0 {
println!("Module Loaded successfully");
}
cfg
},
Err(e) => {

View File

@ -34,8 +34,10 @@ pub struct KloudStore<T> {
// impl<T: Clone> KloudStore<T> { fn into(s: T) -> T { s.clone() } }
impl<T> KloudStore<T> {
pub fn new(data: BTreeMap<String,T>, coll_key: String, data_ctx: DataContext) -> Self {
println!("Loading {} {} items",&coll_key,data.len());
pub fn new(data: BTreeMap<String,T>, coll_key: String, data_ctx: DataContext,verbose: isize) -> Self {
if verbose > 0 {
println!("Loading {} {} items",&coll_key,data.len());
}
Self {
entries: Arc::new(RwLock::new(data)),
data_ctx,