grapl_graph_descriptions_py/
process_inbound_connection_node.rs

1use grapl_graph_descriptions::graph_description::ProcessInboundConnection as InnerProcessInboundConnection;
2use grapl_graph_descriptions::graph_description::ProcessInboundConnectionBuilder;
3
4use pyo3::create_exception;
5use pyo3::prelude::*;
6
7create_exception!(process_inbound_connection_node, ProcessInboundConnectionBuilderError, pyo3::exceptions::ValueError);
8
9#[pyclass]
10#[derive(Clone)]
11pub struct ProcessInboundConnectionNode {
12    pub(crate) inner_node: InnerProcessInboundConnection,
13}
14
15impl<'source> pyo3::FromPyObject<'source> for ProcessInboundConnectionNode {
16    fn extract(ob: &'source pyo3::types::PyAny) -> pyo3::PyResult<Self> {
17        Ok(
18            pyo3::PyTryFrom::try_from(ob).map(|x: &Self| x.clone())?
19        )
20    }
21}
22
23#[pyclass]
24#[derive(Clone, Default)]
25pub struct ProcessInboundConnectionNodeBuilder {
26    builder: ProcessInboundConnectionBuilder,
27}
28
29#[pymethods]
30impl ProcessInboundConnectionNodeBuilder {
31    #[new]
32    fn new(
33        obj: &PyRawObject,
34    ) {
35        obj.init(
36            Self::default()
37        )
38    }
39
40    pub fn with_asset_id(&mut self, asset_id: String) -> Self {
41        self.builder.asset_id(asset_id);
42        self.clone()
43    }
44
45    pub fn with_ip_address(&mut self, src_ip_address: String) -> Self {
46        self.builder.ip_address(src_ip_address);
47        self.clone()
48    }
49
50    pub fn with_port(&mut self, src_port: u16) -> Self {
51        self.builder.port(src_port);
52        self.clone()
53    }
54
55    pub fn with_protocol(&mut self, protocol: String) -> Self {
56        self.builder.protocol(protocol);
57        self.clone()
58    }
59
60    pub fn with_state(&mut self, state: u32) -> Self {
61        self.builder.state(state);
62        self.clone()
63    }
64
65    pub fn with_created_timestamp(&mut self, created_timestamp: u64) -> Self {
66        self.builder.created_timestamp(created_timestamp);
67        self.clone()
68    }
69
70    pub fn with_terminated_timestamp(&mut self, terminated_timestamp: u64) -> Self {
71        self.builder.terminated_timestamp(terminated_timestamp);
72        self.clone()
73    }
74
75    pub fn with_last_seen_timestamp(&mut self, last_seen_timestamp: u64) -> Self {
76        self.builder.last_seen_timestamp(last_seen_timestamp);
77        self.clone()
78    }
79
80    pub fn build(&self) -> PyResult<ProcessInboundConnectionNode> {
81        let built_node = match self.builder.build() {
82            Ok(built_node) => built_node,
83            Err(e) => {
84                return Err(
85                    PyErr::new::<ProcessInboundConnectionBuilderError, _>(format!("{}", e))
86                );
87            }
88        };
89
90        Ok(
91            ProcessInboundConnectionNode {
92                inner_node: built_node
93            }
94        )
95    }
96}