Skip to content

Commit 3653d48

Browse files
committed
fix: Linter and Tests errors
1 parent c9408a8 commit 3653d48

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

tests/events_feed_test.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
from http import HTTPStatus
66
from tools.events_feed.tool import EventsFeedTools
7+
from utils.app_config import AppConfig
78
from .conftest import util_load_json
8-
from unittest.mock import MagicMock, AsyncMock
9+
from unittest.mock import MagicMock, AsyncMock, create_autospec
910
import os
1011

1112
# Get the absolute path of the current module file
@@ -17,19 +18,28 @@
1718
EVENT_INFO_RESPONSE = util_load_json(f"{module_directory}/test_data/events_feed/event_info_response.json")
1819

1920

21+
def mock_app_config() -> AppConfig:
22+
mock_cfg = create_autospec(AppConfig, instance=True)
23+
24+
mock_cfg.sysdig_endpoint.return_value = "https://us2.app.sysdig.com"
25+
mock_cfg.transport.return_value = "stdio"
26+
mock_cfg.log_level.return_value = "DEBUG"
27+
mock_cfg.port.return_value = 8080
28+
29+
return mock_cfg
30+
2031
def test_get_event_info(mock_success_response: MagicMock | AsyncMock, mock_creds) -> None:
2132
"""Test the get_event_info tool method.
2233
Args:
2334
mock_success_response (MagicMock | AsyncMock): Mocked response object.
2435
mock_creds: Mocked credentials.
2536
"""
26-
# Override the environment variable for MCP transport
27-
os.environ["MCP_TRANSPORT"] = "stdio"
2837
# Successful response
2938
mock_success_response.return_value.json.return_value = EVENT_INFO_RESPONSE
3039
mock_success_response.return_value.status_code = HTTPStatus.OK
3140

32-
tools_client = EventsFeedTools()
41+
tools_client = EventsFeedTools(app_config=mock_app_config())
42+
3343
# Pass the mocked Context object
3444
result: dict = tools_client.tool_get_event_info("12345")
3545
results: dict = result["results"]

tools/events_feed/tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def tool_get_event_process_tree(self, event_id: str) -> dict:
189189
190190
Returns:
191191
dict: A dictionary containing the process tree information for the specified event.
192+
193+
Raises:
194+
ToolError: If there is an error constructing or processing the response.
192195
"""
193196
try:
194197
start_time = time.time()

tools/vulnerability_management/tool.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ def tool_get_vulnerability_policy(
304304
response: GetPolicyResponse = vulnerability_api.secure_vulnerability_v1_policies_policy_id_get(policy_id)
305305
return response.model_dump_json() if hasattr(response, "dict") else response
306306
except ToolError as e:
307-
self.log.error(f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_policy_id_get: {e}")
307+
self.log.error(
308+
f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_policy_id_get: {e}"
309+
)
308310
raise e
309311

310312
def tool_list_vulnerability_policies(
@@ -343,7 +345,9 @@ def tool_list_vulnerability_policies(
343345
)
344346
return response
345347
except ToolError as e:
346-
self.log.error(f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_get: {e}")
348+
self.log.error(
349+
f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_get: {e}"
350+
)
347351
raise e
348352

349353
def tool_list_pipeline_scan_results(
@@ -409,7 +413,9 @@ def tool_list_pipeline_scan_results(
409413
)
410414
return response
411415
except ToolError as e:
412-
self.log.error(f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_get: {e}")
416+
self.log.error(
417+
f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_policies_get: {e}"
418+
)
413419
raise e
414420

415421
def tool_get_scan_result(self, scan_id: str) -> dict:
@@ -427,7 +433,9 @@ def tool_get_scan_result(self, scan_id: str) -> dict:
427433
resp: ScanResultResponse = vulnerability_api.secure_vulnerability_v1_results_result_id_get(scan_id)
428434
return resp.model_dump_json() if hasattr(resp, "dict") else resp
429435
except ToolError as e:
430-
self.log.error(f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_results_result_id_get: {e}")
436+
self.log.error(
437+
f"Exception when calling VulnerabilityManagementApi->secure_vulnerability_v1_results_result_id_get: {e}"
438+
)
431439
raise e
432440

433441
def explore_vulnerabilities_prompt(self, filters: str) -> PromptMessage:

utils/app_config.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,38 @@ def __init__(self, config: dict):
2828
def sysdig_endpoint(self) -> str:
2929
"""
3030
Get the Sysdig endpoint from the app config
31+
32+
Returns:
33+
str: The Sysdig API host (e.g., "https://us2.app.sysdig.com").
3134
"""
32-
return self.app_config["sysdig"]["host"]
35+
return os.environ.get("SYSDIG_HOST", self.app_config["sysdig"]["host"])
3336

3437
def transport(self) -> str:
3538
"""
3639
Get the transport protocol (lower case) from the app config
40+
41+
Returns:
42+
str: The transport protocol (e.g., "stdio", "streamable-http", or "sse").
3743
"""
3844
return os.environ.get("MCP_TRANSPORT", self.app_config["mcp"]["transport"]).lower()
3945

40-
@staticmethod
41-
def log_level() -> str:
46+
def log_level(self) -> str:
4247
"""
43-
Get the log level from the app config
48+
Get the log level from the environment or defaults.
49+
50+
Returns:
51+
str: The log level string (e.g., "DEBUG", "INFO", "WARNING", "ERROR").
4452
"""
4553
return os.environ.get("LOGLEVEL", "ERROR")
4654

4755
def port(self) -> int:
4856
"""
4957
Get the port from the app config
58+
59+
Returns:
60+
int: The MCP server port.
5061
"""
51-
return self.app_config["mcp"]["port"]
62+
return os.environ.get("SYSDIG_MCP_PORT", self.app_config["mcp"]["port"])
5263

5364

5465
def env_constructor(loader, node):
@@ -75,7 +86,7 @@ def load_app_config() -> AppConfig:
7586
Load the app config from the YAML file
7687
7788
Returns:
78-
dict: The app config loaded from the YAML file
89+
AppConfig: The loaded application configuration wrapper.
7990
"""
8091
if not check_config_file_exists():
8192
log.error("Config file does not exist")
@@ -100,7 +111,7 @@ def get_app_config() -> AppConfig:
100111
If the config is already loaded, it returns the existing config.
101112
102113
Returns:
103-
dict: The app config loaded from the YAML file, or an empty dict if the file does not exist or is invalid.
114+
AppConfig: The singleton application configuration wrapper.
104115
"""
105116
global _app_config
106117
if _app_config is None:

utils/query_helpers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
def _parse_response_to_obj(results: RESTResponseType | dict | list | str | bytes) -> dict | list:
1414
"""Best-effort conversion of various response types into a Python object.
15-
Returns {} on empty/non-JSON bodies.
15+
16+
Returns:
17+
dict | list: Parsed JSON-compatible object. Returns {} on empty or non-JSON bodies.
1618
"""
1719
# Already a Python structure
1820
if results is None:
@@ -69,10 +71,18 @@ def _parse_response_to_obj(results: RESTResponseType | dict | list | str | bytes
6971
return {}
7072

7173

72-
def create_standard_response(results: RESTResponseType, execution_time_ms: float, **metadata_kwargs) -> dict:
74+
def create_standard_response(results: RESTResponseType, execution_time_ms: float | str, **metadata_kwargs) -> dict:
7375
"""
7476
Creates a standard response format for API calls. Tolerates empty/non-JSON bodies.
75-
Raises ApiException if the HTTP status is >= 300 (when available).
77+
78+
Returns:
79+
dict: A dictionary with keys:
80+
- results: parsed body as dict or list (possibly empty {})
81+
- metadata: includes execution_time_ms (float) and ISO8601 UTC timestamp
82+
- status_code: HTTP status code (int)
83+
84+
Raises:
85+
ApiException: If the HTTP status is >= 300 when status information is available.
7686
"""
7787
status = getattr(results, "status", 200)
7888
reason = getattr(results, "reason", "")

0 commit comments

Comments
 (0)