11"""Client for the CATALYST API."""
22
33import logging
4+ import time
45import uuid
56from datetime import datetime
67from typing import Dict , List , Optional , Tuple
@@ -17,7 +18,7 @@ class CatalystClient:
1718
1819 def __init__ (
1920 self ,
20- api_key : str ,
21+ api_key : str = None ,
2122 base_url : str = "https://prod.blindspot.prodaft.com/api" ,
2223 proxy_url : Optional [str ] = None ,
2324 logger : Optional [logging .Logger ] = None ,
@@ -62,6 +63,7 @@ def __init__(
6263 # extra config params
6364 self .create_observables = create_observables
6465 self .create_indicators = create_indicators
66+ self ._last_request_time = 0
6567
6668 def _handle_request (
6769 self , method : str , endpoint : str , params : Dict = None , data : Dict = None
@@ -83,6 +85,18 @@ def _handle_request(
8385 """
8486 url = f"{ self .base_url } /{ endpoint .lstrip ('/' )} "
8587
88+ if not self .catalyst_authenticated :
89+ current_time = time .time ()
90+ time_since_last_request = current_time - self ._last_request_time
91+ if time_since_last_request < 20 :
92+ sleep_time = 20 - time_since_last_request
93+ if self .logger :
94+ self .logger .debug (
95+ f"Sleeping for { sleep_time :.2f} seconds between requests" # noqa: E231
96+ )
97+ time .sleep (sleep_time )
98+ self ._last_request_time = time .time ()
99+
86100 try :
87101 self .logger .debug (f"Making { method } request to { url } " )
88102 response = self .session .request (
@@ -635,6 +649,12 @@ def create_report_from_member_content_with_references(
635649 for threat_actor in all_entities .get ("threatactor" , []) + all_entities .get (
636650 "threat_actor" , []
637651 ):
652+ if not self .catalyst_authenticated :
653+ if self .logger :
654+ self .logger .debug (
655+ f"Skipping threat actor { threat_actor .get ('value' )} because user is not authenticated... This will be implemented in the future."
656+ )
657+ continue
638658 self ._process_threat_actor (
639659 threat_actor ,
640660 related_objects ,
0 commit comments