karton-core 5.7.0__py3-none-any.whl → 5.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- karton/core/__version__.py +1 -1
- karton/core/asyncio/__init__.py +21 -0
- karton/core/asyncio/backend.py +379 -0
- karton/core/asyncio/base.py +133 -0
- karton/core/asyncio/karton.py +364 -0
- karton/core/asyncio/logger.py +57 -0
- karton/core/asyncio/resource.py +384 -0
- karton/core/backend.py +192 -107
- karton/core/base.py +121 -94
- karton/core/config.py +13 -1
- karton/core/karton.py +35 -22
- karton/core/logger.py +33 -15
- karton/core/main.py +26 -6
- karton/core/resource.py +32 -30
- karton/core/task.py +24 -2
- karton/core/test.py +6 -2
- {karton_core-5.7.0.dist-info → karton_core-5.9.0.dist-info}/METADATA +30 -6
- karton_core-5.9.0.dist-info/RECORD +31 -0
- {karton_core-5.7.0.dist-info → karton_core-5.9.0.dist-info}/WHEEL +1 -1
- karton_core-5.7.0-nspkg.pth +0 -1
- karton_core-5.7.0.dist-info/RECORD +0 -27
- karton_core-5.7.0.dist-info/namespace_packages.txt +0 -1
- {karton_core-5.7.0.dist-info → karton_core-5.9.0.dist-info}/entry_points.txt +0 -0
- {karton_core-5.7.0.dist-info → karton_core-5.9.0.dist-info/licenses}/LICENSE +0 -0
- {karton_core-5.7.0.dist-info → karton_core-5.9.0.dist-info}/top_level.txt +0 -0
karton/core/task.py
CHANGED
@@ -3,6 +3,7 @@ import json
|
|
3
3
|
import time
|
4
4
|
import uuid
|
5
5
|
import warnings
|
6
|
+
from contextvars import ContextVar
|
6
7
|
from typing import (
|
7
8
|
TYPE_CHECKING,
|
8
9
|
Any,
|
@@ -24,6 +25,16 @@ if TYPE_CHECKING:
|
|
24
25
|
|
25
26
|
import orjson
|
26
27
|
|
28
|
+
current_task: ContextVar[Optional["Task"]] = ContextVar("current_task")
|
29
|
+
|
30
|
+
|
31
|
+
def get_current_task() -> Optional["Task"]:
|
32
|
+
return current_task.get(None)
|
33
|
+
|
34
|
+
|
35
|
+
def set_current_task(task: Optional["Task"]):
|
36
|
+
current_task.set(task)
|
37
|
+
|
27
38
|
|
28
39
|
class TaskState(enum.Enum):
|
29
40
|
DECLARED = "Declared" # Task declared in TASKS_QUEUE
|
@@ -375,12 +386,15 @@ class Task(object):
|
|
375
386
|
data: Union[str, bytes],
|
376
387
|
backend: Optional["KartonBackend"] = None,
|
377
388
|
parse_resources: bool = True,
|
389
|
+
resource_unserializer: Optional[Callable[[Dict], Any]] = None,
|
378
390
|
) -> "Task":
|
379
391
|
"""
|
380
392
|
Unserialize Task instance from JSON string
|
381
393
|
|
382
394
|
:param data: JSON-serialized task
|
383
|
-
:param backend:
|
395
|
+
:param backend: |
|
396
|
+
Backend instance to be bound to RemoteResource objects.
|
397
|
+
Deprecated: pass resource_unserializer instead.
|
384
398
|
:param parse_resources: |
|
385
399
|
If set to False (default is True), method doesn't
|
386
400
|
deserialize '__karton_resource__' entries, which speeds up deserialization
|
@@ -388,6 +402,9 @@ class Task(object):
|
|
388
402
|
filtering based on status.
|
389
403
|
When resource deserialization is turned off, Task.unserialize will try
|
390
404
|
to use faster 3rd-party JSON parser (orjson).
|
405
|
+
:param resource_unserializer: |
|
406
|
+
Resource factory used for deserialization of __karton_resource__
|
407
|
+
dictionary values.
|
391
408
|
:return: Unserialized Task object
|
392
409
|
|
393
410
|
:meta private:
|
@@ -399,7 +416,12 @@ class Task(object):
|
|
399
416
|
RemoteResource object instances
|
400
417
|
"""
|
401
418
|
if isinstance(value, dict) and "__karton_resource__" in value:
|
402
|
-
|
419
|
+
if resource_unserializer is None:
|
420
|
+
return RemoteResource.from_dict(
|
421
|
+
value["__karton_resource__"], backend
|
422
|
+
)
|
423
|
+
else:
|
424
|
+
return resource_unserializer(value["__karton_resource__"])
|
403
425
|
return value
|
404
426
|
|
405
427
|
if not isinstance(data, str):
|
karton/core/test.py
CHANGED
@@ -35,8 +35,12 @@ class BackendMock:
|
|
35
35
|
def default_bucket_name(self) -> str:
|
36
36
|
return "karton.test"
|
37
37
|
|
38
|
-
def
|
39
|
-
|
38
|
+
def declare_task(self, task: Task) -> None:
|
39
|
+
# Ensure all local resources have good buckets
|
40
|
+
for resource in task.iterate_resources():
|
41
|
+
if isinstance(resource, LocalResource) and not resource.bucket:
|
42
|
+
resource.bucket = self.default_bucket_name
|
43
|
+
log.debug("Declaring a new task in Redis: %s", task.serialize())
|
40
44
|
|
41
45
|
def set_task_status(self, task: Task, status: TaskState, pipe=None) -> None:
|
42
46
|
log.debug("Setting task %s status to %s", task.uid, status)
|
@@ -1,17 +1,21 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: karton-core
|
3
|
-
Version: 5.
|
3
|
+
Version: 5.9.0
|
4
4
|
Summary: Distributed malware analysis orchestration framework
|
5
|
-
|
5
|
+
License-Expression: BSD-3-Clause
|
6
|
+
Project-URL: Homepage, https://github.com/CERT-Polska/karton
|
7
|
+
Project-URL: Documentation, https://karton-core.readthedocs.io/
|
8
|
+
Project-URL: Repository, https://github.com/CERT-Polska/karton
|
6
9
|
Classifier: Programming Language :: Python :: 3
|
7
10
|
Classifier: Operating System :: OS Independent
|
8
|
-
Classifier: License :: OSI Approved :: BSD License
|
9
11
|
Requires-Python: >=3.8
|
10
12
|
Description-Content-Type: text/markdown
|
11
13
|
License-File: LICENSE
|
12
|
-
Requires-Dist: boto3 <1.36.0
|
13
|
-
Requires-Dist: orjson
|
14
14
|
Requires-Dist: redis
|
15
|
+
Requires-Dist: orjson
|
16
|
+
Requires-Dist: boto3<=1.35.81
|
17
|
+
Requires-Dist: aioboto3==13.3.0
|
18
|
+
Dynamic: license-file
|
15
19
|
|
16
20
|
# Karton <img src="img/logo.svg" width="64">
|
17
21
|
|
@@ -81,6 +85,26 @@ if __name__ == "__main__":
|
|
81
85
|
GenericUnpacker.main()
|
82
86
|
```
|
83
87
|
|
88
|
+
## Command line
|
89
|
+
|
90
|
+
This package also provies a command-line utility called "karton". You can use it for simple management tasks (but it's not designed as a fully capable management tool).
|
91
|
+
|
92
|
+
```
|
93
|
+
$ karton configure # create a new configuration file
|
94
|
+
|
95
|
+
$ karton list -s # list current binds
|
96
|
+
karton name version karton
|
97
|
+
------------------------------------------------------------------------
|
98
|
+
karton.yaramatcher 1.2.0 5.3.0
|
99
|
+
karton.autoit-ripper 1.2.1 5.3.3
|
100
|
+
karton.mwdb-reporter 1.3.0 5.3.2
|
101
|
+
|
102
|
+
$ karton logs # start streaming all system logs
|
103
|
+
|
104
|
+
$ karton delete karton.something # remove unused bind (will be GCed by system during the next operation)
|
105
|
+
```
|
106
|
+
|
107
|
+
|
84
108
|
## Karton systems
|
85
109
|
|
86
110
|
Some Karton systems are universal and useful to everyone. We decided to share them with the community.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
karton/core/__init__.py,sha256=QuT0BWZyp799eY90tK3H1OD2hwuusqMJq8vQwpB3kG4,337
|
2
|
+
karton/core/__version__.py,sha256=K8QUWqtzm0RvyvMi0shZurlcbRE1MiHY43oJIJLcGF0,22
|
3
|
+
karton/core/backend.py,sha256=IhqK-Pia3RjUGHdWEtV7ruFr3w6rhDETrewU3DQo-Pw,41547
|
4
|
+
karton/core/base.py,sha256=mbsZKna9TNqGpvDMwp2nuc9KvlevwOH94ubu0rJvVgk,9178
|
5
|
+
karton/core/config.py,sha256=7nZHQ_25k-dyofohiubOPUBISY3f362gJTh80Igyh4U,8580
|
6
|
+
karton/core/exceptions.py,sha256=8i9WVzi4PinNlX10Cb-lQQC35Hl-JB5R_UKXa9AUKoQ,153
|
7
|
+
karton/core/inspect.py,sha256=aIJQEOEkD5q2xLlV8nhxY5qL5zqcnprP-2DdP6ecKlE,6150
|
8
|
+
karton/core/karton.py,sha256=SUcu1V0Xehq5X5EFp91uaulaefZoF1ObYlEV6VsBZrQ,15522
|
9
|
+
karton/core/logger.py,sha256=UhYCoVARXaatvoJ2lO2mfBHeODOS7z8O-vqdeQhNmV4,2654
|
10
|
+
karton/core/main.py,sha256=2teV0W4W672fzDk6zNcRF77qhhac1_peN3aEWpGXOdQ,9109
|
11
|
+
karton/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
+
karton/core/query.py,sha256=sf24DweVlXfJuBbBD_ns2LXhOV-IBwuPG3jBfTJu77s,12063
|
13
|
+
karton/core/resource.py,sha256=GkU3JGSP1kOsAoblon4BWbQp31eZiDsCjaaDKanEokk,20872
|
14
|
+
karton/core/task.py,sha256=QvAsSUIsyYiRmkgxgugrYkHWH2gczrFDfw2V4izdt1E,19566
|
15
|
+
karton/core/test.py,sha256=TwLXnyNvTvZbnYTjiB4PhW0F_mXiiov4fhLL5Cs2-6I,9349
|
16
|
+
karton/core/utils.py,sha256=sEVqGdVPyYswWuVn8wYXBQmln8Az826N_2HgC__pmW8,4090
|
17
|
+
karton/core/asyncio/__init__.py,sha256=ZgndeKzS3Yg2o8hebwFYJWlCRdW3ImdCOShK4EVmZ14,457
|
18
|
+
karton/core/asyncio/backend.py,sha256=fyOl5kA_KJ-SUyTPzR9ZU5Iz_6vvUb0Je3SVaBQrs6U,13057
|
19
|
+
karton/core/asyncio/base.py,sha256=YDNGyWzgVvt2TnfKvHYbJbcNJaQl95bdBq45YGEo-3Q,4246
|
20
|
+
karton/core/asyncio/karton.py,sha256=sWzwsBBbAhO32TIu7hi0R9HAWlcN_SzgrmaloEgwsgY,12844
|
21
|
+
karton/core/asyncio/logger.py,sha256=BjkbuAeWylTmFjWv8-ckmOGf4nL2Tma96W0nIOc2vwk,1752
|
22
|
+
karton/core/asyncio/resource.py,sha256=86AYm7JeVjEYRNw--h02HIS9xFvgddhktmDUp0qvTO4,12517
|
23
|
+
karton/system/__init__.py,sha256=JF51OqRU_Y4c0unOulvmv1KzSHSq4ZpXU8ZsH4nefRM,63
|
24
|
+
karton/system/__main__.py,sha256=QJkwIlSwaPRdzwKlNmCAL41HtDAa73db9MZKWmOfxGM,56
|
25
|
+
karton/system/system.py,sha256=d_5hhLTthJdr_4gZEGQ6Y-kHvxeBqyQxjjx_wRs3xMA,17285
|
26
|
+
karton_core-5.9.0.dist-info/licenses/LICENSE,sha256=o8h7hYhn7BJC_-DmrfqWwLjaR_Gbe0TZOOQJuN2ca3I,1519
|
27
|
+
karton_core-5.9.0.dist-info/METADATA,sha256=r6CDk__eoUHVC2zufKRsKr64ZGgz_xII1tFSZulMkv4,7788
|
28
|
+
karton_core-5.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
29
|
+
karton_core-5.9.0.dist-info/entry_points.txt,sha256=OgLlsXy61GP6-Yob3oXqeJ2hlRU6LBLj33fr0NufKz0,98
|
30
|
+
karton_core-5.9.0.dist-info/top_level.txt,sha256=X8SslCPsqXDCnGZqrYYolzT3xPzJMq1r-ZQSc0jfAEA,7
|
31
|
+
karton_core-5.9.0.dist-info/RECORD,,
|
karton_core-5.7.0-nspkg.pth
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('karton',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('karton', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('karton', [os.path.dirname(p)])));m = m or sys.modules.setdefault('karton', types.ModuleType('karton'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
|
@@ -1,27 +0,0 @@
|
|
1
|
-
karton_core-5.7.0-nspkg.pth,sha256=vHa-jm6pBTeInFrmnsHMg9AOeD88czzQy-6QCFbpRcM,539
|
2
|
-
karton/core/__init__.py,sha256=QuT0BWZyp799eY90tK3H1OD2hwuusqMJq8vQwpB3kG4,337
|
3
|
-
karton/core/__version__.py,sha256=QmHMXVnw5DVPfWzvN7FS1tOhDAesdxpM_aVOh9CMuSk,22
|
4
|
-
karton/core/backend.py,sha256=_IOjN9pWdSBsDnTMYvg-Fpm6Ag-uf2Jb9LWmrtZqVAU,38773
|
5
|
-
karton/core/base.py,sha256=lqVJvCHRMzvIOpS8SaWlOaSSJBEVkNQe0oClZC_GQYM,8225
|
6
|
-
karton/core/config.py,sha256=M3dB0XgnUO5VzUcGyQa7FyKzmdgmDml1MrzG6CxEuvE,8100
|
7
|
-
karton/core/exceptions.py,sha256=8i9WVzi4PinNlX10Cb-lQQC35Hl-JB5R_UKXa9AUKoQ,153
|
8
|
-
karton/core/inspect.py,sha256=aIJQEOEkD5q2xLlV8nhxY5qL5zqcnprP-2DdP6ecKlE,6150
|
9
|
-
karton/core/karton.py,sha256=l3joJWw8m23wlOErkcQmNFYhLFA5x2la6L0WopxJ7mk,15435
|
10
|
-
karton/core/logger.py,sha256=J3XAyG88U0cwYC9zR6E3QD1uJenrQh7zS9-HgxhqeAs,2040
|
11
|
-
karton/core/main.py,sha256=ir1-dhn3vbwfh2YHiM6ZYfRBbjwLvJSz0d8tuK1mb_4,8310
|
12
|
-
karton/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
karton/core/query.py,sha256=sf24DweVlXfJuBbBD_ns2LXhOV-IBwuPG3jBfTJu77s,12063
|
14
|
-
karton/core/resource.py,sha256=9kWXpMBRfudH0_whJfSSI27K3Gwv2u93CVa7p68Q5UM,20842
|
15
|
-
karton/core/task.py,sha256=gW1szMi5PN2Y06X-Ryo7cmEVluZv1r7W5tvmwIJiD94,18808
|
16
|
-
karton/core/test.py,sha256=cj6W4gNt0BpRjsYiiBt0hPE8dmRfUeIc8sSVkxB50cU,9123
|
17
|
-
karton/core/utils.py,sha256=sEVqGdVPyYswWuVn8wYXBQmln8Az826N_2HgC__pmW8,4090
|
18
|
-
karton/system/__init__.py,sha256=JF51OqRU_Y4c0unOulvmv1KzSHSq4ZpXU8ZsH4nefRM,63
|
19
|
-
karton/system/__main__.py,sha256=QJkwIlSwaPRdzwKlNmCAL41HtDAa73db9MZKWmOfxGM,56
|
20
|
-
karton/system/system.py,sha256=d_5hhLTthJdr_4gZEGQ6Y-kHvxeBqyQxjjx_wRs3xMA,17285
|
21
|
-
karton_core-5.7.0.dist-info/LICENSE,sha256=o8h7hYhn7BJC_-DmrfqWwLjaR_Gbe0TZOOQJuN2ca3I,1519
|
22
|
-
karton_core-5.7.0.dist-info/METADATA,sha256=MrmtycTaYsNB8v0LRyuLIHL2bV17n1Lt6e-ak4RfrH8,6818
|
23
|
-
karton_core-5.7.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
24
|
-
karton_core-5.7.0.dist-info/entry_points.txt,sha256=OgLlsXy61GP6-Yob3oXqeJ2hlRU6LBLj33fr0NufKz0,98
|
25
|
-
karton_core-5.7.0.dist-info/namespace_packages.txt,sha256=X8SslCPsqXDCnGZqrYYolzT3xPzJMq1r-ZQSc0jfAEA,7
|
26
|
-
karton_core-5.7.0.dist-info/top_level.txt,sha256=X8SslCPsqXDCnGZqrYYolzT3xPzJMq1r-ZQSc0jfAEA,7
|
27
|
-
karton_core-5.7.0.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
karton
|
File without changes
|
File without changes
|
File without changes
|