fluidattacks-core 4.1.0__py3-none-any.whl → 4.2.1__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.
@@ -9,7 +9,9 @@ from fluidattacks_core.logging.presets import DATE_FORMAT, PRODUCT_LOGGING
9
9
  from fluidattacks_core.logging.sources.utils import (
10
10
  set_commit_ref_name,
11
11
  set_commit_sha,
12
+ set_product_environment,
12
13
  set_product_id,
14
+ set_product_version,
13
15
  )
14
16
  from fluidattacks_core.logging.utils import set_telemetry_metadata
15
17
 
@@ -50,6 +52,8 @@ __all__ = [
50
52
  "init_uncaught_exception_logging",
51
53
  "set_commit_ref_name",
52
54
  "set_commit_sha",
55
+ "set_product_environment",
53
56
  "set_product_id",
57
+ "set_product_version",
54
58
  "set_telemetry_metadata",
55
59
  ]
@@ -1,3 +1,4 @@
1
+ import copy
1
2
  import logging
2
3
  import sys
3
4
  from logging.handlers import HTTPHandler, QueueHandler, QueueListener
@@ -10,6 +11,22 @@ from fluidattacks_core.logging.filters import NoProductionFilter, ProductionOnly
10
11
  from fluidattacks_core.logging.formatters import ColorfulFormatter, CustomJsonFormatter
11
12
 
12
13
 
14
+ class CustomQueueHandler(QueueHandler):
15
+ """Class to fix QueueHandler missing exc_info field."""
16
+
17
+ def prepare(self, record: logging.LogRecord) -> logging.LogRecord:
18
+ original_exc_info = record.exc_info
19
+
20
+ # Avoid duplicate exc_text in the log message
21
+ no_exc_record = copy.copy(record)
22
+ no_exc_record.exc_info = None
23
+ prepared = super().prepare(no_exc_record)
24
+
25
+ prepared.exc_info = original_exc_info
26
+
27
+ return prepared
28
+
29
+
13
30
  class DebuggingHandler(logging.StreamHandler[TextIO]):
14
31
  """Logging handler for console environments implemented with `QueueHandler`.
15
32
 
@@ -38,7 +55,7 @@ class ProductionSyncHandler(logging.StreamHandler[TextIO]):
38
55
  self.setFormatter(CustomJsonFormatter())
39
56
 
40
57
 
41
- class ProductionAsyncHandler(QueueHandler):
58
+ class ProductionAsyncHandler(CustomQueueHandler):
42
59
  """Logging handler for production environments implemented with `QueueHandler`.
43
60
 
44
61
  Includes:
@@ -96,7 +113,7 @@ class DatadogLogsHandler(HTTPHandler):
96
113
  self.handleError(record)
97
114
 
98
115
 
99
- class TelemetryAsyncHandler(QueueHandler):
116
+ class TelemetryAsyncHandler(CustomQueueHandler):
100
117
  """Logging handler for sending logs to telemetry services asynchronously."""
101
118
 
102
119
  def __init__(self, service: str, source: str, dd_client_token: str) -> None:
@@ -39,10 +39,13 @@ class BatchSource(SourceStrategy):
39
39
 
40
40
  @staticmethod
41
41
  def log_metadata() -> dict[str, str]:
42
- job_name = get_env_var("JOB_DEFINITION_NAME")
42
+ job_name = get_env_var("JOB_NAME")
43
+ job_definition_name = get_env_var("JOB_DEFINITION_NAME")
43
44
  job_queue = get_env_var("AWS_BATCH_JQ_NAME")
44
45
  product_id = get_env_var("PRODUCT_ID")
45
- service = job_name or (f"from-{job_queue}" if job_queue else product_id)
46
+ service = (
47
+ job_name or job_definition_name or (f"from-{job_queue}" if job_queue else product_id)
48
+ )
46
49
  return {
47
50
  "ddsource": "batch",
48
51
  "dd.service": service or "unknown",
@@ -126,7 +129,11 @@ class PipelineSource(SourceStrategy):
126
129
  class ContainerSource(SourceStrategy):
127
130
  @staticmethod
128
131
  def detect() -> bool:
129
- return get_env_var("CONTAINER_IMAGE") is not None
132
+ return (
133
+ get_env_var("CONTAINER_IMAGE") is not None
134
+ or get_env_var("CONTAINER_NAME") is not None
135
+ or get_env_var("CONTAINER_IMAGE_PATH") is not None
136
+ )
130
137
 
131
138
  @staticmethod
132
139
  def log_metadata() -> dict[str, str]:
@@ -1,24 +1,34 @@
1
1
  import os
2
- from typing import Literal
3
2
 
4
3
 
5
4
  def get_env_var(key: str) -> str | None:
6
5
  return os.environ.get(key)
7
6
 
8
7
 
9
- def get_environment() -> Literal["development", "production"]:
8
+ def get_environment() -> str:
9
+ product_environment = os.environ.get("PRODUCT_ENVIRONMENT")
10
10
  branch = os.environ.get("CI_COMMIT_REF_NAME", "default")
11
- return "production" if branch == "trunk" else "development"
11
+ return product_environment or ("production" if branch == "trunk" else "development")
12
12
 
13
13
 
14
14
  def get_version() -> str:
15
- return os.environ.get("CI_COMMIT_SHA", "00000000")[:8]
15
+ product_version = os.environ.get("PRODUCT_VERSION")
16
+ short_commit_sha = os.environ["CI_COMMIT_SHA"][:8] if os.environ.get("CI_COMMIT_SHA") else None
17
+ return product_version or short_commit_sha or "00000000"
16
18
 
17
19
 
18
20
  def set_product_id(product_id: str) -> None:
19
21
  os.environ["PRODUCT_ID"] = product_id
20
22
 
21
23
 
24
+ def set_product_environment(product_environment: str) -> None:
25
+ os.environ["PRODUCT_ENVIRONMENT"] = product_environment
26
+
27
+
28
+ def set_product_version(product_version: str) -> None:
29
+ os.environ["PRODUCT_VERSION"] = product_version
30
+
31
+
22
32
  def set_commit_sha(commit_sha: str) -> None:
23
33
  os.environ["CI_COMMIT_SHA"] = commit_sha
24
34
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fluidattacks-core
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: Fluid Attacks Core Library
5
5
  Author-email: Development <development@fluidattacks.com>
6
6
  License: MPL-2.0
@@ -31,22 +31,22 @@ fluidattacks_core/git/warp.py,sha256=yLotfzBFWSWzM_DzI-hbp4t3hWggKNNGqBr-0mYQhLU
31
31
  fluidattacks_core/http/__init__.py,sha256=3Zz90L6e3_z-M-8Bvk_53rv-CFhPThkRGXnxCiQrmaU,60
32
32
  fluidattacks_core/http/client.py,sha256=jIhtGU2cKi5GZbxHq8WJOPgnk0beScRtxlz9tBSaKuw,2454
33
33
  fluidattacks_core/http/validations.py,sha256=h10Hr906KJqda1rJJb8eOqk1Xyyz81lAJ1glXeae4kM,3766
34
- fluidattacks_core/logging/__init__.py,sha256=FJZC9xf2twcF45NBHEFBJLIC2t3yhuPDOKffYYj7_dM,1434
34
+ fluidattacks_core/logging/__init__.py,sha256=y6D12LrvrsMwaveQn5C4Em3RyeS6mP6E9fRpq7gqS4o,1546
35
35
  fluidattacks_core/logging/filters.py,sha256=v03EWIbCGLKc6sdSQnO7ealxMdPzcJhd20rGr1PBZrE,388
36
36
  fluidattacks_core/logging/formatters.py,sha256=SCA4k9XvHJknmkTv63uiCBU31VrWOsgA7llEXYYj1uQ,6063
37
- fluidattacks_core/logging/handlers.py,sha256=MgUk0ekqq4G_NkbaYu4HQaPIrbWYanTllbF8ydqJBtE,4159
37
+ fluidattacks_core/logging/handlers.py,sha256=7fjCG0AqwlF0PRmH6MwkYRO1qdVoRjyYAAwML3A5lXY,4658
38
38
  fluidattacks_core/logging/presets.py,sha256=KU6d6PI61kklJ_o7NgAzU1DahEPM0KwwjTYHo2naHv8,939
39
39
  fluidattacks_core/logging/utils.py,sha256=jbAcwr0L6iPsId3dYEp-vAbtFex2UUU2l2iIk1F60BE,1115
40
- fluidattacks_core/logging/sources/__init__.py,sha256=YktwsPXXjT3GrZm7FlTAsWiLTcEQ0VQZaaFOeqLlpeY,4646
40
+ fluidattacks_core/logging/sources/__init__.py,sha256=lRd6zhhoRuinh27MtQv5j8nzZfk53e4hzz882_AGXic,4891
41
41
  fluidattacks_core/logging/sources/types.py,sha256=ial-ASN6e0EV7XeetDknjcMx_HjqL6ilFwzNwqw5YyY,338
42
- fluidattacks_core/logging/sources/utils.py,sha256=3pI-114FpJQVG0AB72DuhQjVwj0x353a-e3XW0TueE8,681
42
+ fluidattacks_core/logging/sources/utils.py,sha256=tMoEVqrkVtqMuYtjgG6ih0HOjHyN3tn9G7nZhNoo6IU,1102
43
43
  fluidattacks_core/sarif/__init__.py,sha256=vZkbzafVeqRPEc_dzq6oevZuNp50NNyNGa_eS0oNXnc,101519
44
44
  fluidattacks_core/semver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  fluidattacks_core/semver/match_versions.py,sha256=3L3C0TIVH0AtDpISvk5HHBXFSbJh5V7AINgfKEXYnYI,10157
46
46
  fluidattacks_core/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  fluidattacks_core/serializers/snippet.py,sha256=e520pZHC-fsNuYVNY30A7TcSugvUlFL6xdr74j5aCDM,12780
48
48
  fluidattacks_core/serializers/syntax.py,sha256=DkRsdMyMNrL0pRfsOSVAx79K8F0AmjBk676_d_v7PjM,15908
49
- fluidattacks_core-4.1.0.dist-info/METADATA,sha256=W6a7aqFf2AFjl0hr7QvnVzg0GHZStBI3J0jIxxKgJS8,3199
50
- fluidattacks_core-4.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
- fluidattacks_core-4.1.0.dist-info/top_level.txt,sha256=m49ZyZ2zPQmDBxkSpjb20wr-ZbGVXdOMFBZrDiP5Lb8,18
52
- fluidattacks_core-4.1.0.dist-info/RECORD,,
49
+ fluidattacks_core-4.2.1.dist-info/METADATA,sha256=0O-UKXy3eSmKQDGSpwrNHdrN2Ozet4W8fxoXDP8Wkrc,3199
50
+ fluidattacks_core-4.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
+ fluidattacks_core-4.2.1.dist-info/top_level.txt,sha256=m49ZyZ2zPQmDBxkSpjb20wr-ZbGVXdOMFBZrDiP5Lb8,18
52
+ fluidattacks_core-4.2.1.dist-info/RECORD,,