Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 8203d2f

Browse files
committed
Merge branch 'master' into release/6.6.0 after release 6.5.2
2 parents 907cc73 + 4dd8af6 commit 8203d2f

File tree

8 files changed

+64
-44
lines changed

8 files changed

+64
-44
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ services:
6565
- name: redis
6666
image: redis:7.4.2
6767
- name: elastic
68-
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
68+
image: docker.elastic.co/elasticsearch/elasticsearch:8.17.2
6969
environment:
7070
discovery.type: single-node
7171
xpack.security.enabled: false

pycti/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "6.5.0"
2+
__version__ = "6.5.2"
33

44
from .api.opencti_api_client import OpenCTIApiClient
55
from .api.opencti_api_connector import OpenCTIApiConnector

pycti/api/opencti_api_client.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import io
55
import json
6-
from typing import Union
6+
from typing import Dict, Tuple, Union
77

88
import magic
99
import requests
@@ -88,13 +88,13 @@ class OpenCTIApiClient:
8888
:param log_level: log level for the client
8989
:type log_level: str, optional
9090
:param ssl_verify: Requiring the requests to verify the TLS certificate at the server.
91-
:type ssl_verify: bool, optional
91+
:type ssl_verify: bool, str, optional
9292
:param proxies:
9393
:type proxies: dict, optional, The proxy configuration, would have `http` and `https` attributes. Defaults to {}
9494
```
9595
proxies: {
96-
"http: "http://my_proxy:8080"
97-
"https: "http://my_proxy:8080"
96+
"http": "http://my_proxy:8080"
97+
"https": "http://my_proxy:8080"
9898
}
9999
```
100100
:param json_logging: format the logs as json if set to True
@@ -107,14 +107,14 @@ class OpenCTIApiClient:
107107

108108
def __init__(
109109
self,
110-
url,
111-
token,
110+
url: str,
111+
token: str,
112112
log_level="info",
113-
ssl_verify=False,
114-
proxies=None,
113+
ssl_verify: Union[bool, str] = False,
114+
proxies: Union[Dict[str, str], None] = None,
115115
json_logging=False,
116116
bundle_send_to_queue=True,
117-
cert=None,
117+
cert: Union[str, Tuple[str, str], None] = None,
118118
auth=None,
119119
perform_health_check=True,
120120
):
@@ -762,12 +762,13 @@ def upload_pending_file(self, **kwargs):
762762
data = kwargs.get("data", None)
763763
mime_type = kwargs.get("mime_type", "text/plain")
764764
entity_id = kwargs.get("entity_id", None)
765+
file_markings = kwargs.get("file_markings", [])
765766

766767
if file_name is not None:
767768
self.app_logger.info("Uploading a file.")
768769
query = """
769-
mutation UploadPending($file: Upload!, $entityId: String) {
770-
uploadPending(file: $file, entityId: $entityId) {
770+
mutation UploadPending($file: Upload!, $entityId: String, $file_markings: [String!]) {
771+
uploadPending(file: $file, entityId: $entityId, file_markings: $file_markings) {
771772
id
772773
name
773774
}
@@ -781,7 +782,11 @@ def upload_pending_file(self, **kwargs):
781782
mime_type = magic.from_file(file_name, mime=True)
782783
return self.query(
783784
query,
784-
{"file": (File(file_name, data, mime_type)), "entityId": entity_id},
785+
{
786+
"file": (File(file_name, data, mime_type)),
787+
"entityId": entity_id,
788+
"file_markings": file_markings,
789+
},
785790
)
786791
else:
787792
self.app_logger.error("[upload] Missing parameter: file_name")

pycti/connector/opencti_connector_helper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ class TimeUnit(Enum):
769769
def __init__(self, config: Dict, playbook_compatible=False) -> None:
770770
sys.excepthook = killProgramHook
771771

772+
# Cache
773+
self.stream_collections = {}
774+
772775
# Load API config
773776
self.config = config
774777
self.opencti_url = get_config_variable(
@@ -1063,6 +1066,9 @@ def get_stream_collection(self):
10631066
"stream_live": True,
10641067
"stream_public": False,
10651068
}
1069+
# Get from cache
1070+
elif self.connect_live_stream_id in self.stream_collections:
1071+
return self.stream_collections[self.connect_live_stream_id]
10661072
else:
10671073
query = """
10681074
query StreamCollection($id: String!) {
@@ -1076,6 +1082,10 @@ def get_stream_collection(self):
10761082
}
10771083
"""
10781084
result = self.api.query(query, {"id": self.connect_live_stream_id})
1085+
# Put in cache
1086+
self.stream_collections[self.connect_live_stream_id] = result["data"][
1087+
"streamCollection"
1088+
]
10791089
return result["data"]["streamCollection"]
10801090
else:
10811091
raise ValueError("This connector is not connected to any stream")
@@ -1581,6 +1591,7 @@ def send_stix2_bundle(self, bundle: str, **kwargs) -> list:
15811591
event_version = kwargs.get("event_version", None)
15821592
bypass_validation = kwargs.get("bypass_validation", False)
15831593
entity_id = kwargs.get("entity_id", None)
1594+
file_markings = kwargs.get("file_markings", None)
15841595
file_name = kwargs.get("file_name", None)
15851596
bundle_send_to_queue = kwargs.get("send_to_queue", self.bundle_send_to_queue)
15861597
cleanup_inconsistent_bundle = kwargs.get("cleanup_inconsistent_bundle", False)
@@ -1648,6 +1659,7 @@ def send_stix2_bundle(self, bundle: str, **kwargs) -> list:
16481659
data=bundle,
16491660
mime_type="application/json",
16501661
entity_id=entity_id,
1662+
file_markings=file_markings,
16511663
)
16521664
return []
16531665
elif validation_mode == "draft" and not draft_id:

pycti/utils/opencti_logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import datetime
21
import logging
2+
from datetime import datetime, timezone
33

44
from pythonjsonlogger import jsonlogger
55

@@ -9,8 +9,8 @@ def add_fields(self, log_record, record, message_dict):
99
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
1010
if not log_record.get("timestamp"):
1111
# This doesn't use record.created, so it is slightly off
12-
now = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ")
13-
log_record["timestamp"] = now
12+
now = datetime.now(tz=timezone.utc)
13+
log_record["timestamp"] = now.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
1414
if log_record.get("level"):
1515
log_record["level"] = log_record["level"].upper()
1616
else:

renovate.json

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
{
2-
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"config:base"
5-
],
6-
"labels": [
7-
"dependencies",
8-
"filigran team"
9-
],
10-
"prConcurrentLimit": 2,
11-
"packageRules": [
12-
{
13-
"matchUpdateTypes": ["minor"],
14-
"prPriority": 5
15-
}
16-
],
17-
"timezone": "Europe/Paris",
18-
"schedule": [
19-
"after 10pm and before 5am every weekday",
20-
"every weekend"
21-
],
22-
"updateNotScheduled": false
23-
}
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:recommended"
5+
],
6+
"labels": [
7+
"dependencies",
8+
"filigran team"
9+
],
10+
"prConcurrentLimit": 2,
11+
"packageRules": [
12+
{
13+
"matchUpdateTypes": [
14+
"minor"
15+
],
16+
"prPriority": 5
17+
}
18+
],
19+
"timezone": "Europe/Paris",
20+
"schedule": [
21+
"after 10pm every weekday",
22+
"every weekend",
23+
"before 5am every weekday"
24+
],
25+
"updateNotScheduled": false
26+
}

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ python-magic~=0.4.27; sys_platform == 'linux' or sys_platform == 'darwin'
55
python-magic-bin~=0.4.14; sys_platform == 'win32'
66
python_json_logger~=2.0.4
77
PyYAML~=6.0
8-
pydantic~=2.10.4
8+
pydantic>=2.8.2,<2.11
99
requests~=2.32.2
1010
setuptools~=71.1.0
1111
cachetools~=5.5.0

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_requires =
3737
# Filigran
3838
datefinder~=0.7.3
3939
pika~=1.3.0
40-
pydantic~=2.10.4
40+
pydantic>=2.8.2,<2.11.0
4141
python-magic~=0.4.27; sys_platform == 'linux' or sys_platform == 'darwin'
4242
python-magic-bin~=0.4.14; sys_platform == 'win32'
4343
python_json_logger~=2.0.4
@@ -57,8 +57,8 @@ install_requires =
5757
dev =
5858
black~=24.4.0
5959
build~=1.2.1
60-
isort~=5.13.0
61-
types-pytz~=2024.2.0.20241221
60+
isort~=6.0.0
61+
types-pytz~=2025.1.0.20250204
6262
pre-commit~=3.8.0
6363
pytest-cases~=3.8.0
6464
pytest-cov~=5.0.0

0 commit comments

Comments
 (0)