Skip to content

Commit a37d1d1

Browse files
authored
Merge branch 'main' into ruff-bump
2 parents d9d2e0d + b7fa03e commit a37d1d1

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

contentctl/actions/release_notes.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from contentctl.objects.config import release_notes
2-
from git import Repo
3-
import re
4-
import yaml
51
import pathlib
2+
import re
63
from typing import List, Union
74

5+
import yaml
6+
from git import Repo
7+
8+
from contentctl.objects.config import release_notes
9+
810

911
class ReleaseNotes:
1012
def create_notes(
@@ -171,13 +173,13 @@ def create_notes(
171173

172174
def release_notes(self, config: release_notes) -> None:
173175
### Remove hard coded path
174-
directories = [
175-
"detections/",
176-
"stories/",
177-
"macros/",
178-
"lookups/",
179-
"playbooks/",
180-
"ssa_detections/",
176+
directories: list[pathlib.Path] = [
177+
config.path / "detections",
178+
config.path / "stories",
179+
config.path / "macros",
180+
config.path / "lookups",
181+
config.path / "playbooks",
182+
config.path / "ssa_detections",
181183
]
182184

183185
repo = Repo(config.path)
@@ -229,7 +231,7 @@ def release_notes(self, config: release_notes) -> None:
229231
file_path = pathlib.Path(diff.a_path)
230232

231233
# Check if the file is in the specified directories
232-
if any(str(file_path).startswith(directory) for directory in directories):
234+
if any(file_path.is_relative_to(directory) for directory in directories):
233235
# Check if a file is Modified
234236
if diff.change_type == "M":
235237
modified_files.append(file_path)

contentctl/input/yml_reader.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Dict, Any
2-
import yaml
3-
import sys
41
import pathlib
2+
import sys
3+
from typing import Any, Dict
4+
5+
import yaml
56

67

78
class YmlReader:
@@ -13,40 +14,44 @@ def load_file(
1314
) -> Dict[str, Any]:
1415
try:
1516
file_handler = open(file_path, "r", encoding="utf-8")
17+
except OSError as exc:
18+
print(
19+
f"\nThere was an unrecoverable error when opening the file '{file_path}' - we will exit immediately:\n{str(exc)}"
20+
)
21+
sys.exit(1)
1622

1723
# The following code can help diagnose issues with duplicate keys or
1824
# poorly-formatted but still "compliant" YML. This code should be
1925
# enabled manually for debugging purposes. As such, strictyaml
2026
# library is intentionally excluded from the contentctl requirements
2127

28+
try:
2229
if STRICT_YML_CHECKING:
30+
# This is an extra level of verbose parsing that can be
31+
# enabled for debugging purpose. It is intentionally done in
32+
# addition to the regular yml parsing
2333
import strictyaml
2434

25-
try:
26-
strictyaml.dirty_load(file_handler.read(), allow_flow_style=True)
27-
file_handler.seek(0)
28-
except Exception as e:
29-
print(f"Error loading YML file {file_path}: {str(e)}")
30-
sys.exit(1)
31-
try:
32-
# Ideally we should use
33-
# from contentctl.actions.new_content import NewContent
34-
# and use NewContent.UPDATE_PREFIX,
35-
# but there is a circular dependency right now which makes that difficult.
36-
# We have instead hardcoded UPDATE_PREFIX
37-
UPDATE_PREFIX = "__UPDATE__"
38-
data = file_handler.read()
39-
if UPDATE_PREFIX in data:
40-
raise Exception(
41-
f"The file {file_path} contains the value '{UPDATE_PREFIX}'. Please fill out any unpopulated fields as required."
42-
)
43-
yml_obj = yaml.load(data, Loader=yaml.CSafeLoader)
44-
except yaml.YAMLError as exc:
45-
print(exc)
46-
sys.exit(1)
47-
48-
except OSError as exc:
49-
print(exc)
35+
strictyaml.dirty_load(file_handler.read(), allow_flow_style=True)
36+
file_handler.seek(0)
37+
38+
# Ideally we should use
39+
# from contentctl.actions.new_content import NewContent
40+
# and use NewContent.UPDATE_PREFIX,
41+
# but there is a circular dependency right now which makes that difficult.
42+
# We have instead hardcoded UPDATE_PREFIX
43+
UPDATE_PREFIX = "__UPDATE__"
44+
data = file_handler.read()
45+
if UPDATE_PREFIX in data:
46+
raise Exception(
47+
f"\nThe file {file_path} contains the value '{UPDATE_PREFIX}'. Please fill out any unpopulated fields as required."
48+
)
49+
yml_obj = yaml.load(data, Loader=yaml.CSafeLoader)
50+
51+
except yaml.YAMLError as exc:
52+
print(
53+
f"\nThere was an unrecoverable YML Parsing error when reading or parsing the file '{file_path}' - we will exit immediately:\n{str(exc)}"
54+
)
5055
sys.exit(1)
5156

5257
if add_fields is False:

contentctl/output/templates/savedsearches_detections.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ action.notable.param.severity = high
7373
{% endif %}
7474
{% endif %}
7575
{% if detection.deployment.alert_action.email %}
76+
action.email = 1
7677
action.email.subject.alert = {{ detection.deployment.alert_action.email.subject | custom_jinja2_enrichment_filter(detection) | escapeNewlines() }}
7778
action.email.to = {{ detection.deployment.alert_action.email.to }}
7879
action.email.message.alert = {{ detection.deployment.alert_action.email.message | custom_jinja2_enrichment_filter(detection) | escapeNewlines() }}

0 commit comments

Comments
 (0)