assemblyline_models/messages/
changes.rs

1//! Messages about configuration changes internal to assemblyline.
2
3use serde::{Deserialize, Serialize};
4
5use crate::types::ServiceName;
6
7#[derive(Debug, strum::FromRepr, strum::EnumIs, PartialEq, Eq, Clone, Copy)]
8#[repr(u8)]
9pub enum Operation {
10    Added = 1,
11    Removed = 2,
12    Modified = 3,
13    Incompatible = 4
14}
15
16impl Serialize for Operation {
17    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
18    where
19        S: serde::Serializer {
20        (*self as u8).serialize(serializer)
21    }
22}
23
24impl<'de> Deserialize<'de> for Operation {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
26    where
27        D: serde::Deserializer<'de> {
28        let value = u8::deserialize(deserializer)?;
29        Self::from_repr(value).ok_or(serde::de::Error::custom("could not read service change operation"))
30    }
31}
32
33#[derive(Debug, Serialize, Deserialize)]
34pub struct ServiceChange {
35    pub name: ServiceName,
36    pub operation: Operation,
37    #[serde(default)]
38    pub reason: Option<String>,
39}
40
41#[derive(Debug, Serialize, Deserialize)]
42pub struct HeuristicChange {
43    pub service_name: ServiceName,
44    pub operation: Operation,
45}
46
47
48// @dataclass
49// class SignatureChange:
50//     signature_id: str
51//     signature_type: str
52//     source: str
53//     operation: Operation
54
55//     @staticmethod
56//     def serialize(obj: SignatureChange) -> str:
57//         return json.dumps(asdict(obj))
58
59//     @staticmethod
60//     def deserialize(data: str) -> SignatureChange:
61//         return SignatureChange(**json.loads(data))