grapl_graph_descriptions_py/
process_outbound_connection_node.rs1use grapl_graph_descriptions::graph_description::ProcessOutboundConnection as InnerProcessOutboundConnection;
2use grapl_graph_descriptions::graph_description::ProcessOutboundConnectionBuilder;
3
4use pyo3::create_exception;
5use pyo3::prelude::*;
6
7create_exception!(process_outbound_connection_node, ProcessOutboundConnectionBuilderError, pyo3::exceptions::ValueError);
8
9#[pyclass]
10#[derive(Clone)]
11pub struct ProcessOutboundConnectionNode {
12 inner_node: InnerProcessOutboundConnection,
13}
14
15impl<'source> pyo3::FromPyObject<'source> for ProcessOutboundConnectionNode {
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 ProcessOutboundConnectionNodeBuilder {
26 builder: ProcessOutboundConnectionBuilder,
27}
28
29#[pymethods]
30impl ProcessOutboundConnectionNodeBuilder {
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<ProcessOutboundConnectionNode> {
81
82 let built_node = match self.builder.build() {
83 Ok(built_node) => built_node,
84 Err(e) => {
85 return Err(
86 PyErr::new::<ProcessOutboundConnectionBuilderError, _>(format!("{}", e))
87 )
88 }
89 };
90
91 Ok(
92 ProcessOutboundConnectionNode {
93 inner_node: built_node
94 }
95 )
96 }
97}