Skip to content

Commit f64cba0

Browse files
authored
Add some docstrings and fixes (#1245)
1 parent 9c2f703 commit f64cba0

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

core/schemas/indicators/yara.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,27 @@ def render_with_overlays(cls, pattern, rule_map, overlays):
275275
parsed_rules = plyara.Plyara().parse_string(pattern)
276276
final = ""
277277
for rule in parsed_rules:
278-
db_rule = rule_map.get(rule["rule_name"])
279-
if not db_rule:
280-
raise ValueError(f"Rule {rule['rule_name']} not found in database.")
281-
db_rule.apply_overlays_plyara(overlays, parsed_rule=rule)
282-
final += db_rule.pattern
278+
rule_from_map = rule_map.get(rule["rule_name"])
279+
if not rule_from_map:
280+
logger.warning(
281+
f"Rule {rule['rule_name']} not found in map, it might be a dependency. "
282+
"Skipping overlay application."
283+
)
284+
continue
285+
rule_from_map.apply_overlays_plyara(overlays, parsed_rule=rule)
286+
final += rule_from_map.pattern
283287
return final
284288

285289
def apply_overlays_plyara(
286290
self, overlays: set[str], parsed_rule: dict | None = None
287291
):
288292
"""Apply an overlay to a Yara rule.
289293
294+
Overlays are used to modify the metadata of a Yara rule. The Yara rule's
295+
context attribute will be traversed, looking for `source` matching the
296+
overlay string. If found, the context key-value pairs will be used to
297+
update the Yara rule's metadata section.
298+
290299
Args:
291300
overlay: The overlays to apply.
292301
parsed_rule: The parsed rule to apply the overlays to. If not provided

core/web/apiv2/indicators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ class IndicatorTagResponse(BaseModel):
6666

6767

6868
class YaraBundleRequest(BaseModel):
69+
"""Request to generate a YARA bundle from a list of indicators.
70+
71+
Attributes:
72+
ids: List of YARA IDs to include in the bundle.
73+
tags: List of tags to include in the bundle.
74+
exclude_tags: List of tags to exclude from the bundle.
75+
overlays: Set of overlay names to apply to the bundle. Over
76+
"""
77+
6978
model_config = ConfigDict(extra="forbid")
7079

7180
ids: list[str] = []

0 commit comments

Comments
 (0)