Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve directory for pipelines #238

Merged
merged 6 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sigma/processing/resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass, field
from pathlib import Path
from sigma.exceptions import (
SigmaPipelineNotAllowedForBackendError,
SigmaPipelineNotFoundError,
Expand Down Expand Up @@ -70,17 +71,26 @@ def resolve(
Resolve a list of

* processing pipeline names from pipelines added to the resolver or
* file paths containing processing pipeline YAML definitions
* file paths containing processing pipeline YAML definitions or
* directories containing processing pipelines YAML definitions

into a consolidated processing piepline.
into a consolidated processing pipeline.

If *target* is specified this is passed in each *resolve_pipeline* call to perform a
compatibility check for the usage of the specified backend with the pipeline.
"""
pipelines = []
for spec in pipeline_specs:
spec_path = Path(spec)
if spec_path.is_dir():
for path in spec_path.glob("**/*.yml"):
pipelines.append(self.resolve_pipeline(str(path), target))
else:
pipelines.append(self.resolve_pipeline(spec, target))
return (
sum(
sorted(
[self.resolve_pipeline(spec, target) for spec in pipeline_specs],
pipelines,
key=lambda p: p.priority,
)
)
Expand Down
6 changes: 6 additions & 0 deletions tests/files/pipelines/pipeline-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Test 1
priority: 10
transformations:
- id: test-1
type: field_name_suffix
suffix: .test
6 changes: 6 additions & 0 deletions tests/files/pipelines/pipeline-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Test 2
priority: 20
transformations:
- id: test-2
type: field_name_prefix
prefix: test.
20 changes: 19 additions & 1 deletion tests/test_processing_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
)
from sigma.processing.resolver import ProcessingPipelineResolver
from sigma.processing.pipeline import ProcessingPipeline, ProcessingItem
from sigma.processing.transformations import AddFieldnameSuffixTransformation
from sigma.processing.transformations import (
AddFieldnamePrefixTransformation,
AddFieldnameSuffixTransformation,
)
from collections.abc import Iterable


Expand Down Expand Up @@ -58,6 +61,21 @@ def test_resolve_file(processing_pipeline_resolver: ProcessingPipelineResolver):
)


def test_resolve_directory(processing_pipeline_resolver):
assert processing_pipeline_resolver.resolve(["tests/files/pipelines"]) == ProcessingPipeline(
items=[
ProcessingItem(
AddFieldnameSuffixTransformation(".test"),
identifier="test-1",
),
ProcessingItem(
AddFieldnamePrefixTransformation("test."),
identifier="test-2",
),
],
)


def test_resolve_callable():
pipeline = ProcessingPipeline(
[ProcessingItem(AddFieldnameSuffixTransformation(".item-1"))],
Expand Down