Skip to content

Commit 259ac2d

Browse files
Public Endpoint for non-authenticated users (#3)
* add: tlp:clear reports without apikey * add: tlp:clear reports without apikey
1 parent 3355ee6 commit 259ac2d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python-catalyst"
3-
version = "0.1.0"
3+
version = "0.1.2"
44
description = "Python client for the PRODAFT CATALYST API"
55
readme = "README.md"
66
license = { file = "LICENSE" }

python_catalyst/client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Client for the CATALYST API."""
22

33
import logging
4+
import time
45
import uuid
56
from datetime import datetime
67
from 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,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="python-catalyst",
8-
version="0.1.0",
8+
version="0.1.2",
99
description="Python client for the PRODAFT CATALYST API",
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)