Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
22 changes: 21 additions & 1 deletion python_catalyst/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down