polyswarm-engine 3.2.0__py2.py3-none-any.whl → 3.2.2__py2.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.
@@ -1,5 +1,5 @@
1
1
  # flake8: noqa
2
- __VERSION__ = '3.2.0'
2
+ __VERSION__ = '3.2.2'
3
3
 
4
4
  from .bidutils import (
5
5
  bid_max,
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import contextlib
2
3
  import logging
3
4
  import typing as t
@@ -9,7 +10,12 @@ import celery
9
10
 
10
11
  from polyswarm_engine import exceptions
11
12
  from polyswarm_engine.bounty import get_bounty_expiration, get_bounty_tasked_at, CANNOT_FETCH
12
- from polyswarm_engine.settings import PSENGINE_METADATA_ARCHTECTURE, PSENGINE_METADATA_OS, PSENGINE_DELIVERY_TASK
13
+ from polyswarm_engine.settings import (
14
+ PSENGINE_METADATA_ARCHTECTURE,
15
+ PSENGINE_METADATA_OS,
16
+ PSENGINE_DELIVERY_TASK,
17
+ PSENGINE_DISCARD_EXPIRED_BOUNTIES,
18
+ )
13
19
  from polyswarm_engine.constants import (
14
20
  BENIGN,
15
21
  MALICIOUS,
@@ -245,11 +251,12 @@ class CeleryBackend:
245
251
  expiration = get_bounty_expiration(bounty)
246
252
  processing_start = datetime.now(timezone.utc)
247
253
  if processing_start > expiration:
248
- raise exceptions.EngineTimeoutError(
249
- 'Current time %s is past expiration time %s',
250
- processing_start.isoformat(),
251
- expiration.isoformat(),
252
- )
254
+ if PSENGINE_DISCARD_EXPIRED_BOUNTIES.upper() in ('1', 'YES', 'TRUE'):
255
+ raise exceptions.EngineTimeoutError(
256
+ 'Current time %s is past expiration time %s',
257
+ processing_start.isoformat(),
258
+ expiration.isoformat(),
259
+ )
253
260
 
254
261
  try:
255
262
  result = self._analyze(bounty)
@@ -44,7 +44,21 @@ def rescale_to_bid(bounty: 'Bounty', value: 't.SupportsInt', min=0, max=100) ->
44
44
 
45
45
 
46
46
  def dni_to_bid(bounty: 'Bounty', value: str) -> 'Bid':
47
- """Transform string value from the None / Low / Med / High scale to a bid"""
47
+ """Transform string value from the None / Low / Med / High scale to a bid
48
+
49
+ From: https://www.dni.gov/files/documents/ICD/ICD_203_TA_Analytic_Standards_21_Dec_2022.pdf
50
+
51
+ | DNI Scale | Polyswarm Bid |
52
+ |-----------------------------------------+---------------|
53
+ | Not Specified | Not Specified |
54
+ | Almost No Chance / Remote | 5 |
55
+ | Very Unlikely / Highly Improbable | 15 |
56
+ | Unlikely / Improbable | 30 |
57
+ | Roughly Even Chance / Roughly Even Odds | 50 |
58
+ | Likely / Probable | 70 |
59
+ | Very Likely / Highly Probable | 85 |
60
+ | Almost Certain / Nearly Certain | 95 |to appropriate bid amounts.
61
+ """
48
62
  value = value.lower()
49
63
 
50
64
  if value == "none":
@@ -1,11 +1,20 @@
1
1
  import functools
2
2
  import importlib
3
+ import io
4
+ import os
5
+ import sys
6
+ import logging
3
7
 
8
+ from celery.apps.worker import Worker
4
9
  from celery.worker.consumer import mingle, gossip
5
10
  from celery.worker.worker import WorkController
11
+ import click
6
12
 
7
13
  import polyswarm_engine.settings
8
14
 
15
+ logger = logging.getLogger(__name__)
16
+
17
+
9
18
  # monkey patch to enable -Ofair, the most stable during our tests
10
19
  _original_setup_defaults = WorkController.setup_defaults
11
20
  @functools.wraps(WorkController.setup_defaults)
@@ -17,6 +26,25 @@ WorkController.setup_defaults = _new_setup_defaults
17
26
  mingle.Mingle.compatible_transports = {}
18
27
  gossip.Gossip.compatible_transports = {}
19
28
 
29
+
30
+ # monkey patch to make emit_banner use logging instead of print(sys.__stdout__)
31
+ _original_emit_banner = Worker.emit_banner
32
+ @functools.wraps(Worker.emit_banner)
33
+ def _log_emit_banner(self):
34
+ original_stdout = sys.__stdout__
35
+ sys.__stdout__ = buffer = io.StringIO()
36
+ try:
37
+ _original_emit_banner(self)
38
+ finally:
39
+ sys.__stdout__ = original_stdout
40
+ banner_text = buffer.getvalue()
41
+ if os.getenv('LOG_FORMAT') == 'json':
42
+ # Celery outputs the banner as Cyan via ASCII terminal magic
43
+ banner_text = click.unstyle(banner_text)
44
+ logger.info(banner_text.lstrip())
45
+ Worker.emit_banner = _log_emit_banner
46
+
47
+
20
48
  ##########################################
21
49
  # Celery Configuration
22
50
  ##########################################
@@ -86,7 +86,7 @@ def get_logging(log_level=None, handler='console'):
86
86
  'click': {
87
87
  'level': log_level,
88
88
  'class': 'click_log.core.ClickHandler',
89
- 'formatter': 'click',
89
+ 'formatter': 'click' if LOG_FORMAT == 'text' else LOG_FORMAT,
90
90
  },
91
91
  },
92
92
  'loggers': {
@@ -1,3 +1,4 @@
1
+ from __future__ import annotations
1
2
  import os
2
3
  import platform
3
4
  import shutil
@@ -39,3 +40,6 @@ PSENGINE_TASK_ALWAYS_EAGER: bool = bool(int(os.getenv('PSENGINE_TASK_ALWAYS_EAGE
39
40
  #: Name of the Celery task that processes the delivery of assertions and votes.
40
41
  # If empty, fallback to doing the delivery directly via HTTP
41
42
  PSENGINE_DELIVERY_TASK = os.getenv('PSENGINE_DELIVERY_TASK', '')
43
+
44
+ #: Turn on (set as 1) to discard bounties arrived after the expiration.
45
+ PSENGINE_DISCARD_EXPIRED_BOUNTIES = os.getenv('PSENGINE_DISCARD_EXPIRED_BOUNTIES', '')
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyswarm_engine
3
- Version: 3.2.0
3
+ Version: 3.2.2
4
4
  Summary: Polyswarm engine libarary
5
5
  Author-email: Polyswarm Developers <developers@polyswarm.io>
6
6
  Project-URL: Homepage, https://github.com/polyswarm/polyswarm_engine
7
- Requires-Python: <4,>=3.10
7
+ Requires-Python: <4,>=3.8
8
8
  Description-Content-Type: text/markdown
9
9
  Requires-Dist: celery
10
10
  Requires-Dist: click
@@ -12,6 +12,7 @@ Requires-Dist: click-log
12
12
  Requires-Dist: python-json-logger
13
13
  Requires-Dist: requests
14
14
  Provides-Extra: tests
15
+ Requires-Dist: pathlib3x; python_version < "3.10" and extra == "tests"
15
16
  Requires-Dist: flake8; extra == "tests"
16
17
  Requires-Dist: isort; extra == "tests"
17
18
  Requires-Dist: mypy; extra == "tests"
@@ -1,21 +1,21 @@
1
- polyswarm_engine/__init__.py,sha256=y9ToCb4bOwGo1f-RwO6eyxcxTke8P-QVBCULHEUEFes,838
2
- polyswarm_engine/backend.py,sha256=3Sf-nBPME8SAUHNE9Yuoa8Hw7cPr7o01iEjGmGXgxls,11387
3
- polyswarm_engine/bidutils.py,sha256=5Ipi5mAV2uxUp-TPUf39MmC81nIGBlyFyLIV-DWU03k,2111
1
+ polyswarm_engine/__init__.py,sha256=B1P69VVyBIoRQSgfG9zjfp77zKYOsI81jw61pq-J5jw,838
2
+ polyswarm_engine/backend.py,sha256=yqkduAdAMwxeKnfaQIaacwZMFyKlvwEgXKXqmA0r-X8,11580
3
+ polyswarm_engine/bidutils.py,sha256=E-Oo7-LCCe5lNnoMKEmVDLW6lErqdkaTPfWoL-9YhJk,2881
4
4
  polyswarm_engine/bounty.py,sha256=gAHbApVqz07isKhzVSp4WX9PTic4Z0gTF_Lim9i0GE0,12627
5
- polyswarm_engine/celeryconfig.py,sha256=xirgl2YMru8CeTB3xpq3u0OoxBGoC7rEgW6_ytqePC0,2831
5
+ polyswarm_engine/celeryconfig.py,sha256=7_mgzcegdgg5UOW_Iyach1HdsnpcVKr2uP8DZ9Npk-c,3610
6
6
  polyswarm_engine/cli.py,sha256=NwQmK1dFaROlfzrSqvQg5xPJVoDOC1-IWtH2xFrtirY,11278
7
7
  polyswarm_engine/command.py,sha256=RwdMpDeCvO0YM-7zKdej6o-8-zw_E8ltqxJ3MQvF2vw,915
8
8
  polyswarm_engine/constants.py,sha256=zeQRLSmYZH2kerzj5-S7ogsEloePreS2OsTQIw-lYeI,1379
9
9
  polyswarm_engine/engine.py,sha256=y7-wopHYTmCfyljJq4TbqKkOgz-Z5bQRvFv5liZhGcg,3789
10
10
  polyswarm_engine/exceptions.py,sha256=KEffKHrhX-2_ujoF9IBquMF5iq0amqP5uUkxoqkp31E,900
11
- polyswarm_engine/log_config.py,sha256=Dyzd30_zQtfRqPT7o2kQO1DgySzU4L1ykQDjUxnrbUk,3544
11
+ polyswarm_engine/log_config.py,sha256=NnC4f5ukBW16LoXEskaIb98hi7LGZlOWv2F5OvuZf5A,3584
12
12
  polyswarm_engine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- polyswarm_engine/settings.py,sha256=d200Oy0MKc2z6xFFhRuu9IU5BrrgbrjKCFY6QGBgAjw,1984
13
+ polyswarm_engine/settings.py,sha256=kqANh7JTMWu8_FOf_5l2tLFANoSM9jDxjnNYMzg5HBA,2179
14
14
  polyswarm_engine/typing.py,sha256=Z6nroMW-xsR0uuJuUfsi7IQPEt_ydBa2pYUYTeFqUmI,3685
15
15
  polyswarm_engine/utils.py,sha256=2-ghShvJG8jsmNCpS4yv_1FH0r0pg2r67GvQru8v9aE,15492
16
16
  polyswarm_engine/wine.py,sha256=f01TEFv5Mvzv4_nGuEo1zYK19CJHAEFqJ4-8rva0xJA,4581
17
17
  polyswarm_engine/wsgi.py,sha256=9vv1WR0Rzcz7qYeReUrQw0ESHpK_3VbpMcIbmJiul-Q,4197
18
- polyswarm_engine-3.2.0.dist-info/METADATA,sha256=x7XZqf3KKq0fLKFlO2EVl75oxCXsKK_EPPcfstLQNYs,34233
19
- polyswarm_engine-3.2.0.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
20
- polyswarm_engine-3.2.0.dist-info/top_level.txt,sha256=iEEYOgxT_azXd38CWlfY_W0xOhxFBzBnwmfe62g96Pk,17
21
- polyswarm_engine-3.2.0.dist-info/RECORD,,
18
+ polyswarm_engine-3.2.2.dist-info/METADATA,sha256=doXtO-XtWW7j4YV5X2Ro0MzwuiQns0sGQg2_3VXqklk,34303
19
+ polyswarm_engine-3.2.2.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
20
+ polyswarm_engine-3.2.2.dist-info/top_level.txt,sha256=iEEYOgxT_azXd38CWlfY_W0xOhxFBzBnwmfe62g96Pk,17
21
+ polyswarm_engine-3.2.2.dist-info/RECORD,,