assemblyline_models/datastore/
retrohunt.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_with::{SerializeDisplay, DeserializeFromStr};
4use struct_metadata::Described;
5
6use crate::{ElasticMeta, types::{Sha256, ClassificationString, Text, ExpandingClassification}};
7
8#[derive(SerializeDisplay, DeserializeFromStr, Debug, PartialEq, Eq, strum::Display, strum::EnumString, Described, Clone, Copy)]
9#[metadata_type(ElasticMeta)]
10#[strum(serialize_all = "snake_case")]
11pub enum IndexCatagory {
12 Hot = 1,
13 Archive = 2,
14 HotAndArchive = 3,
15}
16
17#[derive(Serialize, Deserialize, Debug, Described, Clone)]
19#[metadata_type(ElasticMeta)]
20#[metadata(index=true, store=true)]
21pub struct Retrohunt {
22 pub indices: IndexCatagory,
24 #[serde(flatten)]
26 pub classification: ExpandingClassification,
27 #[metadata(mapping="keyword")]
29 pub search_classification: ClassificationString,
30 #[metadata(copyto="__text__")]
32 pub creator: String,
33 #[metadata(copyto="__text__")]
35 pub description: Text,
36 #[metadata(store=false)]
40 pub expiry_ts: Option<DateTime<Utc>>,
41
42 pub start_group: u32,
44 pub end_group: u32,
46
47 pub created_time: DateTime<Utc>,
49 pub started_time: DateTime<Utc>,
51 #[metadata(store=false)]
53 pub completed_time: Option<DateTime<Utc>>,
54
55 pub key: String,
57 #[metadata(store=false)]
59 pub raw_query: String,
60 #[metadata(store=false, copyto="__text__")]
62 pub yara_signature: String,
63
64 #[metadata(store=false)]
66 pub errors: Vec<String>,
67 #[metadata(store=false)]
69 pub warnings: Vec<String>,
70 pub finished: bool,
72 pub truncated: bool,
74}
75
76#[derive(Serialize, Deserialize, Debug, Described, Clone, PartialEq, Eq)]
78#[metadata_type(ElasticMeta)]
79#[metadata(index=true, store=true)]
80pub struct RetrohuntHit {
81 pub key: String,
83 #[serde(flatten)]
85 pub classification: ExpandingClassification,
86 pub sha256: Sha256,
87 #[metadata(store=false)]
89 pub expiry_ts: Option<DateTime<Utc>>,
90 pub search: String,
91}
92
93#[cfg(test)]
94mod test {
95 use chrono::Utc;
96
97 use super::RetrohuntHit;
98 use crate::{serialize::test::setup_classification, types::ExpandingClassification};
99
100 #[test]
101 fn hit_roundtrip(){
102 let parser = setup_classification();
103 let data = RetrohuntHit {
104 key: "abc123".to_owned(),
105 classification: ExpandingClassification::new("L0".to_owned(), &parser).unwrap(),
106 sha256: "cb3f7b194d220004ffa6eef1305849bcef38033c49cb1b16c5ab3c3d60bd9d20".parse().unwrap(),
107 expiry_ts: Utc::now().into(),
108 search: "search".to_owned(),
109 };
110
111 let json = serde_json::to_string_pretty(&data).unwrap();
112 println!("{json}");
113 let data_copy = serde_json::from_str(&json).unwrap();
114 assert_eq!(data, data_copy);
115 }
116}