Skip to content

Commit

Permalink
Update create_signal function to accept datetime object for the creat…
Browse files Browse the repository at this point in the history
…ed_at argument
  • Loading branch information
TheophileDiot committed Feb 8, 2024
1 parent 6a779a9 commit 0232a01
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/cscapi/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
from typing import Union
import uuid
from datetime import timezone
from datetime import datetime, timezone

from dacite import from_dict
from dateutil import parser as datetimeparser
Expand All @@ -26,13 +27,11 @@ def generate_machine_id_from_key(key, prefix: str = "", length=48) -> str:


def create_signal(
attacker_ip: str, scenario: str, created_at: str, machine_id: str, **kwargs
attacker_ip: str, scenario: str, created_at: Union[str, datetime], machine_id: str, **kwargs
) -> SignalModel:
created_at = (
datetimeparser.parse(created_at)
.astimezone(timezone.utc)
.strftime("%Y-%m-%dT%H:%M:%S%z")
)
if isinstance(created_at, str):
created_at = datetimeparser.parse(created_at)
created_at = created_at.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z")

if "start_at" not in kwargs:
kwargs["start_at"] = created_at
Expand Down

0 comments on commit 0232a01

Please sign in to comment.