grapl_graph_descriptions_py/
ip_connection_node.rs1use grapl_graph_descriptions::graph_description::IpConnection as InnerIpConnection;
2use grapl_graph_descriptions::graph_description::IpConnectionBuilder;
3
4use pyo3::create_exception;
5use pyo3::prelude::*;
6
7create_exception!(ip_connection_node, IpConnectionBuilderError, pyo3::exceptions::ValueError);
8
9#[pyclass]
10#[derive(Clone)]
11pub struct IpConnectionNode {
12 inner_node: InnerIpConnection,
13}
14
15impl<'source> pyo3::FromPyObject<'source> for IpConnectionNode {
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
24#[pyclass]
25#[derive(Clone, Default)]
26pub struct IpConnectionNodeBuilder {
27 builder: IpConnectionBuilder,
28}
29
30#[pymethods]
31impl IpConnectionNodeBuilder {
32 #[new]
33 fn new(
34 obj: &PyRawObject,
35 ) {
36 obj.init(
37 Self::default()
38 )
39 }
40
41
42 pub fn with_src_ip_address(&mut self, src_ip_address: String) -> Self {
43 self.builder.src_ip_address(src_ip_address);
44 self.clone()
45 }
46
47 pub fn with_dst_ip_address(&mut self, dst_ip_address: String) -> Self {
48 self.builder.dst_ip_address(dst_ip_address);
49 self.clone()
50 }
51
52 pub fn with_protocol(&mut self, protocol: String) -> Self {
53 self.builder.protocol(protocol);
54 self.clone()
55 }
56
57 pub fn with_state(&mut self, state: u32) -> Self {
58 self.builder.state(state);
59 self.clone()
60 }
61
62 pub fn with_created_timestamp(&mut self, created_timestamp: u64) -> Self {
63 self.builder.created_timestamp(created_timestamp);
64 self.clone()
65 }
66
67 pub fn with_terminated_timestamp(&mut self, terminated_timestamp: u64) -> Self {
68 self.builder.terminated_timestamp(terminated_timestamp);
69 self.clone()
70 }
71
72 pub fn with_last_seen_timestamp(&mut self, last_seen_timestamp: u64) -> Self {
73 self.builder.last_seen_timestamp(last_seen_timestamp);
74 self.clone()
75 }
76
77
78 pub fn build(&self) -> PyResult<IpConnectionNode> {
79
80 let built_node = match self.builder.build() {
81 Ok(built_node) => built_node,
82 Err(e) => {
83 return Err(
84 PyErr::new::<IpConnectionBuilderError, _>(format!("{}", e))
85 )
86 }
87 };
88
89 Ok(
90 IpConnectionNode {
91 inner_node: built_node
92 }
93 )
94 }
95}