Update: store toml rules in config.rs - Singleton
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::toml;
|
||||||
use clap::{App, AppSettings, Arg, ArgMatches};
|
use clap::{App, AppSettings, Arg, ArgMatches};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
@@ -8,6 +9,7 @@ pub struct SingletonReader {
|
|||||||
pub regex: Vec<Vec<String>>,
|
pub regex: Vec<Vec<String>>,
|
||||||
pub whitelist: Vec<Vec<String>>,
|
pub whitelist: Vec<Vec<String>>,
|
||||||
pub args: ArgMatches<'static>,
|
pub args: ArgMatches<'static>,
|
||||||
|
pub rules: toml::ParseToml,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Lang {
|
pub enum Lang {
|
||||||
@@ -19,12 +21,16 @@ pub fn singleton() -> Box<SingletonReader> {
|
|||||||
static mut SINGLETON: Option<Box<SingletonReader>> = Option::None;
|
static mut SINGLETON: Option<Box<SingletonReader>> = Option::None;
|
||||||
static ONCE: Once = Once::new();
|
static ONCE: Once = Once::new();
|
||||||
|
|
||||||
|
let mut toml = toml::ParseToml::new();
|
||||||
|
&toml.read_dir("rules".to_string());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ONCE.call_once(|| {
|
ONCE.call_once(|| {
|
||||||
let singleton = SingletonReader {
|
let singleton = SingletonReader {
|
||||||
regex: read_csv("regexes.txt"),
|
regex: read_csv("regexes.txt"),
|
||||||
whitelist: read_csv("whitelist.txt"),
|
whitelist: read_csv("whitelist.txt"),
|
||||||
args: build_app().get_matches(),
|
args: build_app().get_matches(),
|
||||||
|
rules: toml,
|
||||||
};
|
};
|
||||||
|
|
||||||
SINGLETON = Some(Box::new(singleton));
|
SINGLETON = Some(Box::new(singleton));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
use crate::detections::configs::{singleton, Lang};
|
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|||||||
@@ -6,12 +6,9 @@ use std::{fs, path::PathBuf, process};
|
|||||||
use yamato_event_analyzer::detections::configs;
|
use yamato_event_analyzer::detections::configs;
|
||||||
use yamato_event_analyzer::detections::detection;
|
use yamato_event_analyzer::detections::detection;
|
||||||
use yamato_event_analyzer::omikuji::Omikuji;
|
use yamato_event_analyzer::omikuji::Omikuji;
|
||||||
use yamato_event_analyzer::toml;
|
|
||||||
|
|
||||||
fn main() -> Result<(), DeError> {
|
fn main() -> Result<(), DeError> {
|
||||||
configs::singleton();
|
configs::singleton();
|
||||||
let mut toml = toml::ParseToml::new();
|
|
||||||
&toml.read_dir("rules".to_string());
|
|
||||||
|
|
||||||
let filepath: String = configs::singleton()
|
let filepath: String = configs::singleton()
|
||||||
.args
|
.args
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Rule {
|
pub struct Rule {
|
||||||
pub severity: Option<String>,
|
pub severity: Option<String>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub message: Option<String>,
|
pub message: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Toml {
|
pub struct Toml {
|
||||||
pub rule: Rule,
|
pub rule: Rule,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::io;
|
|||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct ParseToml {
|
pub struct ParseToml {
|
||||||
pub rules: Vec<Result<rule::Toml, toml::de::Error>>,
|
pub rules: Vec<Result<rule::Toml, toml::de::Error>>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user