Skip to content

Commit

Permalink
feat(signal): Update create_signal function to accept datetime object…
Browse files Browse the repository at this point in the history
… for the created_at argument (#16)
  • Loading branch information
TheophileDiot authored Feb 9, 2024
1 parent 6a779a9 commit cc1a501
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 cc1a501

Please sign in to comment.