assemblyline_models/datastore/
retrohunt.rsuse chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};
use serde_with::{SerializeDisplay, DeserializeFromStr};
use struct_metadata::Described;
use crate::{Sha256, ElasticMeta, ClassificationString, Text, ExpandingClassification};
#[derive(SerializeDisplay, DeserializeFromStr, Debug, PartialEq, Eq, strum::Display, strum::EnumString, Described, Clone, Copy)]
#[metadata_type(ElasticMeta)]
#[strum(serialize_all = "snake_case")]
pub enum IndexCatagory {
Hot = 1,
Archive = 2,
HotAndArchive = 3,
}
#[derive(Serialize, Deserialize, Debug, Described, Clone)]
#[metadata_type(ElasticMeta)]
#[metadata(index=true, store=true)]
pub struct Retrohunt {
pub indices: IndexCatagory,
#[serde(flatten)]
pub classification: ExpandingClassification,
pub search_classification: ClassificationString,
#[metadata(copyto="__text__")]
pub creator: String,
#[metadata(copyto="__text__")]
pub description: Text,
#[metadata(store=false)]
pub expiry_ts: Option<DateTime<Utc>>,
pub start_group: u32,
pub end_group: u32,
pub created_time: DateTime<Utc>,
pub started_time: DateTime<Utc>,
#[metadata(store=false)]
pub completed_time: Option<DateTime<Utc>>,
pub key: String,
#[metadata(store=false)]
pub raw_query: String,
#[metadata(store=false, copyto="__text__")]
pub yara_signature: String,
#[metadata(store=false)]
pub errors: Vec<String>,
#[metadata(store=false)]
pub warnings: Vec<String>,
pub finished: bool,
pub truncated: bool,
}
#[derive(Serialize, Deserialize, Debug, Described, Clone, PartialEq, Eq)]
#[metadata_type(ElasticMeta)]
#[metadata(index=true, store=true)]
pub struct RetrohuntHit {
pub key: String,
#[serde(flatten)]
pub classification: ExpandingClassification,
pub sha256: Sha256,
#[metadata(store=false)]
pub expiry_ts: Option<DateTime<Utc>>,
pub search: String,
}
#[cfg(test)]
mod test {
use chrono::Utc;
use super::RetrohuntHit;
use crate::{serialize::test::setup_classification, ExpandingClassification};
#[test]
fn hit_roundtrip(){
setup_classification();
let data = RetrohuntHit {
key: "abc123".to_owned(),
classification: ExpandingClassification::new("L0".to_owned()).unwrap(),
sha256: "cb3f7b194d220004ffa6eef1305849bcef38033c49cb1b16c5ab3c3d60bd9d20".parse().unwrap(),
expiry_ts: Utc::now().into(),
search: "search".to_owned(),
};
let json = serde_json::to_string_pretty(&data).unwrap();
println!("{json}");
let data_copy = serde_json::from_str(&json).unwrap();
assert_eq!(data, data_copy);
}
}