Skip to content

Commit 4d0294f

Browse files
committed
Added logic to main.py to use the created_at and updated_at values from the ndjson file if they exist.
1 parent 7a54ae3 commit 4d0294f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

detection_rules/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ def import_rules_into_repo( # noqa: PLR0912, PLR0913, PLR0915
247247
if isinstance(contents["author"], str):
248248
contents["author"] = [contents["author"]]
249249

250+
if "created_at" in contents:
251+
try:
252+
contents["creation_date"] = datetime.strptime(
253+
contents["created_at"], "%Y-%m-%dT%H:%M:%S.%fZ"
254+
).strftime("%Y/%m/%d")
255+
except ValueError:
256+
pass
257+
258+
if "updated_at" in contents:
259+
try:
260+
contents["updated_date"] = datetime.strptime(
261+
contents["updated_at"], "%Y-%m-%dT%H:%M:%S.%fZ"
262+
).strftime("%Y/%m/%d")
263+
except ValueError:
264+
pass
265+
250266
contents.update(
251267
update_metadata_from_file(
252268
rule_path, {"creation_date": local_creation_date, "updated_date": local_updated_date}

0 commit comments

Comments
 (0)