Skip to content

Commit 4dbedb2

Browse files
authored
Merge pull request #296 from SigmaHQ/pass-backend-options-to-pipeline
Pass backend options to pipeline
2 parents fc60de2 + 272ab95 commit 4dbedb2

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

sigma/backends/test/backend.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ def __init__(
164164
processing_pipeline: Optional[ProcessingPipeline] = None,
165165
collect_errors: bool = False,
166166
testparam: Optional[str] = None,
167+
**kwargs,
167168
):
168-
super().__init__(processing_pipeline, collect_errors)
169+
super().__init__(processing_pipeline, collect_errors, **kwargs)
169170
self.testparam = testparam
170171

171172
def finalize_query_test(self, rule, query, index, state):

sigma/conversion/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ def __init__(
143143
self,
144144
processing_pipeline: Optional[ProcessingPipeline] = None,
145145
collect_errors: bool = False,
146+
**backend_options: Dict,
146147
):
147148
self.processing_pipeline = processing_pipeline
148149
self.errors = list()
149150
self.collect_errors = collect_errors
151+
self.backend_options = backend_options
150152

151153
def convert(
152154
self,
@@ -183,6 +185,9 @@ def convert_rule(self, rule: SigmaRule, output_format: Optional[str] = None) ->
183185
+ self.processing_pipeline
184186
+ self.output_format_processing_pipeline[output_format or self.default_format]
185187
)
188+
self.last_processing_pipeline.vars.update(
189+
{"backend_" + key: value for key, value in self.backend_options.items()}
190+
)
186191

187192
error_state = "applying processing pipeline on"
188193
self.last_processing_pipeline.apply(rule) # 1. Apply transformations

tests/test_conversion_base.py

+33-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sigma.processing.conditions import IncludeFieldCondition
77
from sigma.processing.finalization import ConcatenateQueriesFinalizer
88
from sigma.processing.pipeline import ProcessingPipeline, ProcessingItem, QueryPostprocessingItem
9-
from sigma.processing.postprocessing import EmbedQueryTransformation
9+
from sigma.processing.postprocessing import EmbedQueryTransformation, QueryTemplateTransformation
1010
from sigma.processing.transformations import (
1111
AddFieldnamePrefixTransformation,
1212
AddFieldnameSuffixTransformation,
@@ -80,6 +80,38 @@ def test_backend_pipeline_with_postprocessing():
8080
)
8181

8282

83+
def test_backend_options_passing_to_pipeline():
84+
test_backend = TextQueryTestBackend(
85+
ProcessingPipeline(
86+
postprocessing_items=[
87+
QueryPostprocessingItem(
88+
QueryTemplateTransformation(
89+
"query='{{query}}', state={{pipeline.vars.backend_test}}"
90+
)
91+
)
92+
]
93+
),
94+
test="testvalue",
95+
)
96+
result = test_backend.convert(
97+
SigmaCollection.from_yaml(
98+
"""
99+
title: Test
100+
status: test
101+
logsource:
102+
category: test_category
103+
product: test_product
104+
detection:
105+
sel:
106+
field: value
107+
condition: sel
108+
"""
109+
)
110+
)
111+
assert test_backend.last_processing_pipeline.vars["backend_test"] == "testvalue"
112+
assert result == ["query='field=\"value\"', state=testvalue"]
113+
114+
83115
def test_backend_and_custom_pipeline(test_backend):
84116
assert (
85117
test_backend.convert(

0 commit comments

Comments
 (0)