Skip to main content

stix_rs/observables/
process.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub struct Process {
7    pub name: Option<String>,
8    pub pid: Option<u32>,
9    pub command_line: Option<String>,
10    pub created: Option<DateTime<Utc>>,
11    #[serde(flatten)]
12    pub custom_properties: std::collections::HashMap<String, serde_json::Value>,
13}
14
15impl Process {
16    pub fn builder() -> ProcessBuilder { ProcessBuilder::default() }
17}
18
19#[derive(Debug, Default)]
20pub struct ProcessBuilder { name: Option<String>, pid: Option<u32>, command_line: Option<String>, created: Option<DateTime<Utc>>, custom_properties: std::collections::HashMap<String, serde_json::Value> }
21
22impl ProcessBuilder {
23    pub fn name(mut self, n: impl Into<String>) -> Self { self.name = Some(n.into()); self }
24    pub fn pid(mut self, p: u32) -> Self { self.pid = Some(p); self }
25    pub fn command_line(mut self, c: impl Into<String>) -> Self { self.command_line = Some(c.into()); self }
26    pub fn created(mut self, t: DateTime<Utc>) -> Self { self.created = Some(t); self }
27    pub fn property(mut self, k: impl Into<String>, v: impl Into<serde_json::Value>) -> Self { self.custom_properties.insert(k.into(), v.into()); self }
28    pub fn build(self) -> Process { Process { name: self.name, pid: self.pid, command_line: self.command_line, created: self.created, custom_properties: self.custom_properties } }
29}
30
31impl From<Process> for crate::StixObjectEnum { fn from(p: Process) -> Self { crate::StixObjectEnum::Process(p) } }