Skip to content

Commit fdd1adb

Browse files
committed
chore: Remediate Vulnerabilites across all repos
1 parent 86f2181 commit fdd1adb

File tree

6 files changed

+95
-32
lines changed

6 files changed

+95
-32
lines changed

requirements-dev.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ commitizen>=3.12
3333
mkdocs>=1.5
3434
mkdocs-material>=9.0
3535
termcolor==2.3.0
36+
37+
# Security: Fix pip-audit vulnerabilities
38+
requests>=2.32.4
39+
urllib3>=2.5.0

requirements-dev.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
5-
# pip-compile --output-file=requirements-dev.txt --strip-extras requirements-dev.in requirements-dev.in
5+
# pip-compile requirements-dev.in
66
#
77
annotated-types==0.7.0
88
# via pydantic
@@ -60,7 +60,7 @@ commitizen==4.8.3
6060
# via -r requirements-dev.in
6161
contourpy==1.3.2
6262
# via matplotlib
63-
coverage==7.9.1
63+
coverage[toml]==7.9.1
6464
# via pytest-cov
6565
cryptography==45.0.4
6666
# via authlib
@@ -258,6 +258,7 @@ regex==2024.11.6
258258
requests==2.32.4
259259
# via
260260
# -r D:\git\stock-tech-patterns\requirements.in
261+
# -r requirements-dev.in
261262
# hvac
262263
# mkdocs-material
263264
# safety
@@ -316,8 +317,10 @@ typing-extensions==4.14.0
316317
# typer
317318
tzdata==2025.2
318319
# via pandas
319-
urllib3==2.4.0
320+
urllib3==2.5.0
320321
# via
322+
# -r D:\git\stock-tech-patterns\requirements.in
323+
# -r requirements-dev.in
321324
# botocore
322325
# requests
323326
watchdog==6.0.0

requirements.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ matplotlib>=3.6.0,<4.0
1616
#vault integration
1717
hvac>=1.2.1,<2.0.0
1818
prometheus_client>=0.17.1
19+
20+
# Security: Fix pip-audit vulnerabilities
21+
requests>=2.32.4
22+
urllib3>=2.5.0

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is autogenerated by pip-compile with Python 3.12
33
# by the following command:
44
#
5-
# pip-compile --output-file=requirements.txt --strip-extras requirements.in requirements.in
5+
# pip-compile requirements.in
66
#
77
boto3==1.38.36
88
# via -r requirements.in
@@ -78,8 +78,9 @@ six==1.17.0
7878
# via python-dateutil
7979
tzdata==2025.2
8080
# via pandas
81-
urllib3==2.4.0
81+
urllib3==2.5.0
8282
# via
83+
# -r requirements.in
8384
# botocore
8485
# requests
8586
win32-setctime==1.2.0

src/app/utils/types.py

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
"""Shared enums and validation helpers used across the application."""
1+
"""Shared enums and validation helpers used across the application.
2+
3+
NOTE: This file is maintained in `repo-utils-shared/src/app/utils/types.py`
4+
and should be synchronized across repositories using the sync script.
5+
Do not modify it directly in individual repositories.
6+
"""
27

38
from enum import Enum
4-
from typing import Any
9+
from typing import Any, TypedDict
510

611

712
class OutputMode(str, Enum):
@@ -16,51 +21,73 @@ class OutputMode(str, Enum):
1621

1722

1823
class PollerType(str, Enum):
19-
"""Defines the domain of the poller for routing/behavior."""
24+
"""Defines the domain of the poller for routing and behavior."""
2025

2126
STOCK = "stock"
2227
SENTIMENT = "sentiment"
2328
ALT = "alt"
29+
CRYPTO = "crypto"
30+
FUND = "fund"
31+
ANALYSIS = "analysis"
32+
BACKTEST = "backtest"
33+
UI = "ui"
34+
35+
36+
class ValidatedMessage(TypedDict):
37+
"""Validated and enriched message with required structure."""
38+
39+
symbol: str
40+
timestamp: str
41+
data: dict[str, Any]
2442

2543

2644
def validate_dict(data: dict[str, Any], required_keys: list[str]) -> bool:
2745
"""Check that all required keys are present in the dictionary.
2846
29-
Parameters
30-
----------
31-
data : dict[str, Any]
32-
The dictionary to validate.
33-
34-
required_keys : list[str]
35-
Keys that must exist in the dictionary.
47+
Args:
48+
data: The dictionary to validate.
49+
required_keys: Keys that must exist in the dictionary.
3650
37-
Returns
38-
-------
39-
bool
51+
Returns:
4052
True if all required keys are present, False otherwise.
41-
4253
"""
4354
return all(k in data for k in required_keys)
4455

4556

4657
def validate_list_of_dicts(data: Any, required_keys: list[str]) -> bool:
47-
"""Validate that the input is a list of dicts, each containing the required
48-
keys.
49-
50-
Parameters
51-
----------
52-
data : Any
53-
The object to validate.
58+
"""Validate that the input is a list of dicts, each with required keys.
5459
55-
required_keys : list[str]
56-
Keys that must exist in each dictionary.
60+
Args:
61+
data: The object to validate.
62+
required_keys: Keys that must exist in each dictionary.
5763
58-
Returns
59-
-------
60-
bool
64+
Returns:
6165
True if input is a list of valid dicts, False otherwise.
62-
6366
"""
6467
if not isinstance(data, list):
6568
return False
6669
return all(isinstance(item, dict) and validate_dict(item, required_keys) for item in data)
70+
71+
72+
def is_valid_payload(data: Any) -> bool:
73+
"""Perform basic schema validation for a generic payload.
74+
75+
Args:
76+
data: The input data to validate.
77+
78+
Returns:
79+
True if the input is a dict with minimum expected structure.
80+
"""
81+
return isinstance(data, dict) and "symbol" in data and "timestamp" in data
82+
83+
84+
def is_valid_batch(data: Any) -> bool:
85+
"""Validate a batch of payloads.
86+
87+
Args:
88+
data: The input to validate.
89+
90+
Returns:
91+
True if input is a list of valid payload dictionaries.
92+
"""
93+
return validate_list_of_dicts(data, ["symbol", "timestamp"])

src/app/utils/validate_data.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ def validate_data(data: dict[str, Any]) -> bool:
6161
return True
6262

6363

64+
def validate_message_schema(message: Any) -> bool:
65+
"""Validate a generic message for required fields: 'symbol', 'timestamp', and 'data' (dict).
66+
67+
Used for verifying incoming message format before processing.
68+
69+
Parameters
70+
----------
71+
message : Any
72+
The input message to validate.
73+
74+
Returns
75+
-------
76+
bool
77+
True if message contains required fields and structure.
78+
"""
79+
if not isinstance(message, dict):
80+
return False
81+
if not all(k in message for k in ("symbol", "timestamp", "data")):
82+
return False
83+
if not isinstance(message["data"], dict):
84+
return False
85+
return True
86+
87+
6488
def _validate_symbol(symbol: str) -> bool:
6589
"""Validate that the 'symbol' field is a string of alphabetical characters.
6690

0 commit comments

Comments
 (0)