diff --git a/pyproject.toml b/pyproject.toml index d510526..7a86865 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "python-catalyst" -version = "0.1.0" +version = "0.1.2" description = "Python client for the PRODAFT CATALYST API" readme = "README.md" license = { file = "LICENSE" } diff --git a/python_catalyst/client.py b/python_catalyst/client.py index 31153ca..261b22f 100644 --- a/python_catalyst/client.py +++ b/python_catalyst/client.py @@ -1,6 +1,7 @@ """Client for the CATALYST API.""" import logging +import time import uuid from datetime import datetime from typing import Dict, List, Optional, Tuple @@ -17,7 +18,7 @@ class CatalystClient: def __init__( self, - api_key: str, + api_key: str = None, base_url: str = "https://prod.blindspot.prodaft.com/api", proxy_url: Optional[str] = None, logger: Optional[logging.Logger] = None, @@ -62,6 +63,7 @@ def __init__( # extra config params self.create_observables = create_observables self.create_indicators = create_indicators + self._last_request_time = 0 def _handle_request( self, method: str, endpoint: str, params: Dict = None, data: Dict = None @@ -83,6 +85,18 @@ def _handle_request( """ url = f"{self.base_url}/{endpoint.lstrip('/')}" + if not self.catalyst_authenticated: + current_time = time.time() + time_since_last_request = current_time - self._last_request_time + if time_since_last_request < 20: + sleep_time = 20 - time_since_last_request + if self.logger: + self.logger.debug( + f"Sleeping for {sleep_time:.2f} seconds between requests" # noqa: E231 + ) + time.sleep(sleep_time) + self._last_request_time = time.time() + try: self.logger.debug(f"Making {method} request to {url}") response = self.session.request( @@ -635,6 +649,12 @@ def create_report_from_member_content_with_references( for threat_actor in all_entities.get("threatactor", []) + all_entities.get( "threat_actor", [] ): + if not self.catalyst_authenticated: + if self.logger: + self.logger.debug( + f"Skipping threat actor {threat_actor.get('value')} because user is not authenticated... This will be implemented in the future." + ) + continue self._process_threat_actor( threat_actor, related_objects, diff --git a/setup.py b/setup.py index 946bced..fa45584 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="python-catalyst", - version="0.1.0", + version="0.1.2", description="Python client for the PRODAFT CATALYST API", long_description=long_description, long_description_content_type="text/markdown",