Update: store toml rules in config.rs - Singleton

This commit is contained in:
itiB
2020-11-05 19:40:04 +09:00
parent 77df2fcc9c
commit 28d5731ef0
5 changed files with 9 additions and 6 deletions

View File

@@ -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<Vec<String>>,
pub whitelist: Vec<Vec<String>>,
pub args: ArgMatches<'static>,
pub rules: toml::ParseToml,
}
pub enum Lang {
@@ -19,12 +21,16 @@ pub fn singleton() -> Box<SingletonReader> {
static mut SINGLETON: Option<Box<SingletonReader>> = 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));

View File

@@ -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;

View File

@@ -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

View File

@@ -1,14 +1,14 @@
extern crate serde;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct Rule {
pub severity: Option<String>,
pub name: Option<String>,
pub message: Option<String>,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct Toml {
pub rule: Rule,
}

View File

@@ -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<Result<rule::Toml, toml::de::Error>>,
}