Skip to content

Commit

Permalink
refactor: fixed clippy error
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Oct 10, 2023
1 parent 19a1dda commit 20b310a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
15 changes: 9 additions & 6 deletions src/afterfact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ pub fn set_output_color(no_color_flag: bool) -> HashMap<CompactString, Colors> {
if no_color_flag {
return color_map;
}
if read_result.is_err() {
// color情報がない場合は通常の白色の出力が出てくるのみで動作への影響を与えない為warnとして処理する
AlertMessage::warn(read_result.as_ref().unwrap_err()).ok();
return color_map;
}
read_result.unwrap().iter().for_each(|line| {
let color_map_contents = match read_result {
Ok(c) => c,
Err(e) => {
// color情報がない場合は通常の白色の出力が出てくるのみで動作への影響を与えない為warnとして処理する
AlertMessage::warn(&e).ok();
return color_map;
}
};
color_map_contents.iter().for_each(|line| {
if line.len() != 2 {
return;
}
Expand Down
47 changes: 27 additions & 20 deletions src/detections/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use compact_str::CompactString;
use hashbrown::{HashMap, HashSet};
use itertools::Itertools;
use lazy_static::lazy_static;
use nested::Nested;
use regex::Regex;
use std::env::current_exe;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1679,13 +1678,16 @@ impl TargetIds {

fn load_target_ids(path: &str) -> TargetIds {
let mut ret = TargetIds::default();
let lines = utils::read_txt(path); // ファイルが存在しなければエラーとする
if lines.is_err() {
AlertMessage::alert(lines.as_ref().unwrap_err()).ok();
return ret;
}
let lines = match utils::read_txt(path) {
Ok(lines) => lines,
Err(e) => {
// ファイルが存在しなければエラーとする
AlertMessage::alert(&e).ok();
return ret;
}
};

for line in lines.unwrap_or_else(|_| Nested::<String>::new()).iter() {
for line in lines.iter() {
if line.is_empty() {
continue;
}
Expand Down Expand Up @@ -1980,8 +1982,8 @@ pub fn load_eventkey_alias(path: &str) -> EventKeyAliasConfig {

// eventkey_aliasが読み込めなかったらエラーで終了とする。
let read_result = utils::read_csv(path);
if read_result.is_err() {
AlertMessage::alert(read_result.as_ref().unwrap_err()).ok();
if let Err(e) = read_result {
AlertMessage::alert(&e).ok();
return config;
}

Expand Down Expand Up @@ -2011,12 +2013,15 @@ pub fn load_eventkey_alias(path: &str) -> EventKeyAliasConfig {

///設定ファイルを読み込み、keyとfieldsのマップをPIVOT_KEYWORD大域変数にロードする。
pub fn load_pivot_keywords(path: &str) {
let read_result = utils::read_txt(path);
if read_result.is_err() {
AlertMessage::alert(read_result.as_ref().unwrap_err()).ok();
}
let read_result = match utils::read_txt(path) {
Ok(v) => v,
Err(e) => {
AlertMessage::alert(&e).ok();
return;
}
};

read_result.unwrap().iter().for_each(|line| {
read_result.iter().for_each(|line| {
let mut map = line.split('.').take(2);
if let Some(size) = map.size_hint().1 {
if size < 2 {
Expand Down Expand Up @@ -2453,14 +2458,16 @@ impl EventInfoConfig {
fn load_eventcode_info(path: &str) -> EventInfoConfig {
let mut infodata = EventInfo::new();
let mut config = EventInfoConfig::new();
let read_result = utils::read_csv(path);
if read_result.is_err() {
AlertMessage::alert(read_result.as_ref().unwrap_err()).ok();
return config;
}
let read_result = match utils::read_csv(path) {
Ok(v) => v,
Err(e) => {
AlertMessage::alert(&e).ok();
return config;
}
};

// channel_eid_info.txtが読み込めなかったらエラーで終了とする。
read_result.unwrap().iter().for_each(|line| {
read_result.iter().for_each(|line| {
if line.len() != 3 {
return;
}
Expand Down
14 changes: 8 additions & 6 deletions src/detections/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ pub fn create_output_filter_config(
is_lower_case: bool,
) -> HashMap<CompactString, CompactString> {
let mut ret: HashMap<CompactString, CompactString> = HashMap::new();
let read_result = utils::read_csv(path);
if read_result.is_err() {
AlertMessage::alert(read_result.as_ref().unwrap_err()).ok();
return HashMap::default();
}
read_result.unwrap().iter().for_each(|line| {
let read_result = match utils::read_csv(path) {
Ok(c) => c,
Err(e) => {
AlertMessage::alert(&e).ok();
return HashMap::default();
}
};
read_result.iter().for_each(|line| {
if line.len() != 2 {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/options/level_tuning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ impl LevelTuning {
rules_path: &str,
stored_static: &StoredStatic,
) -> Result<(), String> {
let read_result = utils::read_csv(level_tuning_config_path);
if read_result.is_err() {
return Result::Err(read_result.as_ref().unwrap_err().to_string());
}
let read_result = match utils::read_csv(level_tuning_config_path) {
Ok(c) => c,
Err(e) => return Result::Err(e.to_string()),
};

// Read Tuning files
let mut tuning_map: HashMap<String, String> = HashMap::new();
read_result.unwrap().iter().try_for_each(|line| -> Result<(), String> {
read_result.iter().try_for_each(|line| -> Result<(), String> {
// 1つ目の要素も存在しない場合はread_csvの段階で読み飛ばされるためget(0)がNoneにはならない
let id = line.get(0).unwrap();
if !configs::IDS_REGEX.is_match(id) {
Expand Down

0 comments on commit 20b310a

Please sign in to comment.