add rule parser actions

This commit is contained in:
fukusuket
2025-03-09 20:12:28 +09:00
parent fc9643fbd5
commit c9149bbb6c
2 changed files with 27 additions and 3 deletions

21
.github/workflows/create-rule-meta.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: create-rule-meta.json
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout self repository
uses: actions/checkout@v4
- name: Checkout hayabusa-rules
uses: actions/checkout@v4
with:
repository: Yamato-Security/hayabusa-rules
path: hayabusa-rules
- name: Run
run: cd wela-extractor && cargo run --release -- ../../hayabusa-rules ../config/eid_subcategory_mapping-org.csv ../config/hayabusa-rule-meta.json

View File

@@ -108,18 +108,20 @@ fn load_event_id_guid_pairs(file_path: &str) -> Result<Vec<(String, String)>, Bo
fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
if args.len() != 4 {
eprintln!("Usage: {} <file_path> <dir>", args[0]);
std::process::exit(1);
}
let file_path = &args[1];
let eid_subcategory_pair = load_event_id_guid_pairs(file_path).unwrap();
let eid_subcategory_pair = load_event_id_guid_pairs(file_path)?;
let dir = &args[2];
let yml_files = list_yml_files(dir);
let mut results = Vec::new();
let out = &args[3];
for file in yml_files {
let contents = fs::read_to_string(&file).expect("Unable to read file");
let docs = YamlLoader::load_from_str(&contents).expect("Unable to parse YAML");
@@ -131,6 +133,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
let json_output = serde_json::to_string_pretty(&results)?;
write("../config/hayabusa_rules_meta.json", json_output)?;
println!("{}", json_output);
write(out, json_output)?;
Ok(())
}