11from pathlib import Path
2- from typing import Dict , List , Optional , Union
2+ from typing import Dict , List , Optional , Union , Any
33
44from pydantic import BaseModel , Field , HttpUrl , SecretStr , validator
55
66
7- class WebhookForwarderConfiguration (BaseModel ):
7+ class BasicFilter (BaseModel ):
8+ """A filter that matches objects based on attribute values.
9+
10+ This filter checks if an object has a specific attribute and whether
11+ the attribute's value is in a predefined list of allowed values.
12+
13+ Attributes:
14+ attribute: The name of the attribute to check on the target object.
15+ values: List of acceptable values for the attribute.
16+ """
17+
18+ attribute : str
19+ values : List [str ]
20+
21+ def matches (self , obj : Any ) -> bool :
22+ """Check if the given object matches this filter.
23+
24+ The object matches if it has the specified attribute and the
25+ attribute's value is in the list of allowed values.
26+
27+ Args:
28+ obj: The object to check against this filter.
29+
30+ Returns:
31+ True if the object has the attribute and its value is in the
32+ allowed values list, False otherwise.
33+ """
34+ if not hasattr (obj , self .attribute ):
35+ return False
36+ value = getattr (obj , self .attribute )
37+ return value in self .values
38+
39+
40+ class ForwarderConfiguration (BaseModel ):
41+ enable : bool = Field (default = False )
42+ """Enable the forwarder. Defaults to False."""
43+
44+ topics : List [str ] = Field (default_factory = lambda : ["enriched-network-dpi" , "enriched-network-alert" ])
45+ """List of topics to forward. Defaults to ["enriched-network-dpi", "enriched-network-alert"]."""
46+
47+ configuration_file : Path = None
48+ """Configuration file path, only set when loaded from a drop-in configuration."""
49+
50+ filters : List [BasicFilter ] = []
51+ """List of filters. Defaults to []."""
52+
53+
54+ class WebhookForwarderConfiguration (ForwarderConfiguration ):
855 """Configuration for the Webhook Forwarder.
956
1057 This class defines the destination, authentication, and reliability settings
@@ -23,9 +70,6 @@ class WebhookForwarderConfiguration(BaseModel):
2370 url : Union [HttpUrl , str ]
2471 """The destination URL for the webhook (must be a valid HTTP/HTTPS URL)."""
2572
26- configuration_file : Path = None
27- """Configuration file path, only set when loaded from a drop-in configuration."""
28-
2973 headers : Dict [str , str ] = Field (default_factory = dict )
3074 """Optional dictionary of additional HTTP headers to include in requests."""
3175
@@ -50,12 +94,6 @@ class WebhookForwarderConfiguration(BaseModel):
5094 timeout : float = Field (default = 10.0 , gt = 0 )
5195 """Request timeout in seconds. Defaults to 10.0."""
5296
53- enable : bool = Field (default = False )
54- """Enable the forwarder. Defaults to False."""
55-
56- topics : List [str ] = Field (default_factory = lambda : ["enriched-network-dpi" , "enriched-network-alert" ])
57- """List of topics to forward. Defaults to ["enriched-network-dpi", "enriched-network-alert"]."""
58-
5997 # Forwarding modes
6098 mode : str = Field (default = "immediate" ) # immediate, bulk, periodic
6199 """Forwarding mode ('immediate', 'bulk', 'periodic'). Defaults to 'immediate'."""
@@ -94,7 +132,7 @@ def validate_auth_token(cls, v, values):
94132 return v
95133
96134
97- class FileForwarderConfiguration (BaseModel ):
135+ class FileForwarderConfiguration (ForwarderConfiguration ):
98136 """Configuration for the File Forwarder."""
99137
100138 output_dir : str = "output"
0 commit comments