diff --git a/src/detections/configs.rs b/src/detections/configs.rs index ab5dc0c7..c59eff94 100644 --- a/src/detections/configs.rs +++ b/src/detections/configs.rs @@ -1,3 +1,4 @@ +use crate::toml; use clap::{App, AppSettings, Arg, ArgMatches}; use std::fs::File; use std::io::prelude::*; @@ -8,6 +9,7 @@ pub struct SingletonReader { pub regex: Vec>, pub whitelist: Vec>, pub args: ArgMatches<'static>, + pub rules: toml::ParseToml, } pub enum Lang { @@ -19,12 +21,16 @@ pub fn singleton() -> Box { static mut SINGLETON: Option> = Option::None; static ONCE: Once = Once::new(); + let mut toml = toml::ParseToml::new(); + &toml.read_dir("rules".to_string()); + unsafe { ONCE.call_once(|| { let singleton = SingletonReader { regex: read_csv("regexes.txt"), whitelist: read_csv("whitelist.txt"), args: build_app().get_matches(), + rules: toml, }; SINGLETON = Some(Box::new(singleton)); diff --git a/src/detections/print.rs b/src/detections/print.rs index 670a6f7c..ac12a1d1 100644 --- a/src/detections/print.rs +++ b/src/detections/print.rs @@ -1,6 +1,5 @@ extern crate chrono; extern crate lazy_static; -use crate::detections::configs::{singleton, Lang}; use chrono::{DateTime, TimeZone, Utc}; use lazy_static::lazy_static; use std::collections::BTreeMap; diff --git a/src/main.rs b/src/main.rs index 5eb2d00e..ffbce6e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,9 @@ use std::{fs, path::PathBuf, process}; use yamato_event_analyzer::detections::configs; use yamato_event_analyzer::detections::detection; use yamato_event_analyzer::omikuji::Omikuji; -use yamato_event_analyzer::toml; fn main() -> Result<(), DeError> { configs::singleton(); - let mut toml = toml::ParseToml::new(); - &toml.read_dir("rules".to_string()); let filepath: String = configs::singleton() .args diff --git a/src/models/rule.rs b/src/models/rule.rs index fa1ca510..f385e596 100644 --- a/src/models/rule.rs +++ b/src/models/rule.rs @@ -1,14 +1,14 @@ extern crate serde; use serde::Deserialize; -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Rule { pub severity: Option, pub name: Option, pub message: Option, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Clone)] pub struct Toml { pub rule: Rule, } diff --git a/src/toml.rs b/src/toml.rs index 08482f88..94cdfce3 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -7,6 +7,7 @@ use std::io; use std::io::{BufReader, Read}; use std::path::{Path, PathBuf}; +#[derive(Clone)] pub struct ParseToml { pub rules: Vec>, }