use crate::engine::interfaces::{Layer, ProcessingStep};
use serde::{Deserialize, Serialize};
use validator::{Validate, ValidationErrors};
use super::legacy;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct FlowConfig {
pub connection: ProcessingStep,
}
impl Validate for FlowConfig {
fn validate(&self) -> Result<(), ValidationErrors> {
super::validator::validate_flow_config(&self.connection, Layer::L4, "tcp")
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum TcpConfig {
Flow(FlowConfig),
Legacy(legacy::LegacyTcpConfig),
}
impl Validate for TcpConfig {
fn validate(&self) -> Result<(), ValidationErrors> {
match self {
Self::Legacy(config) => {
let mut result = config.validate();
if let Err(e) = legacy::validate_tcp_rules(&config.rules) {
match result {
Ok(()) => {
let mut errors = ValidationErrors::new();
errors.add("rules", e);
result = Err(errors);
}
Err(ref mut errors) => {
errors.add("rules", e);
}
}
}
result
}
Self::Flow(config) => config.validate(),
}
}
}