forked from HomeLab/unraid-mcp
fix: resolve ruff lint issues in storage tool and tests
- Move _ALLOWED_LOG_PREFIXES to module level (N806: constant naming)
- Use f-string conversion flag {e!s} instead of {str(e)} (RUF010)
- Fix import block sorting in both files (I001)
This commit is contained in:
@@ -8,6 +8,7 @@ from conftest import make_tool_fn
|
|||||||
from unraid_mcp.core.exceptions import ToolError
|
from unraid_mcp.core.exceptions import ToolError
|
||||||
from unraid_mcp.tools.storage import format_bytes
|
from unraid_mcp.tools.storage import format_bytes
|
||||||
|
|
||||||
|
|
||||||
# --- Unit tests for helpers ---
|
# --- Unit tests for helpers ---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ from ..config.logging import logger
|
|||||||
from ..core.client import DISK_TIMEOUT, make_graphql_request
|
from ..core.client import DISK_TIMEOUT, make_graphql_request
|
||||||
from ..core.exceptions import ToolError
|
from ..core.exceptions import ToolError
|
||||||
|
|
||||||
|
|
||||||
|
_ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/")
|
||||||
|
|
||||||
QUERIES: dict[str, str] = {
|
QUERIES: dict[str, str] = {
|
||||||
"shares": """
|
"shares": """
|
||||||
query GetSharesInfo {
|
query GetSharesInfo {
|
||||||
@@ -99,7 +102,6 @@ def register_storage_tool(mcp: FastMCP) -> None:
|
|||||||
if action == "logs":
|
if action == "logs":
|
||||||
if not log_path:
|
if not log_path:
|
||||||
raise ToolError("log_path is required for 'logs' action")
|
raise ToolError("log_path is required for 'logs' action")
|
||||||
_ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/")
|
|
||||||
# Normalize path to prevent traversal attacks (e.g. /var/log/../../etc/shadow)
|
# Normalize path to prevent traversal attacks (e.g. /var/log/../../etc/shadow)
|
||||||
normalized = posixpath.normpath(log_path)
|
normalized = posixpath.normpath(log_path)
|
||||||
if not any(normalized.startswith(p) for p in _ALLOWED_LOG_PREFIXES):
|
if not any(normalized.startswith(p) for p in _ALLOWED_LOG_PREFIXES):
|
||||||
@@ -165,6 +167,6 @@ def register_storage_tool(mcp: FastMCP) -> None:
|
|||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in unraid_storage action={action}: {e}", exc_info=True)
|
logger.error(f"Error in unraid_storage action={action}: {e}", exc_info=True)
|
||||||
raise ToolError(f"Failed to execute storage/{action}: {str(e)}") from e
|
raise ToolError(f"Failed to execute storage/{action}: {e!s}") from e
|
||||||
|
|
||||||
logger.info("Storage tool registered successfully")
|
logger.info("Storage tool registered successfully")
|
||||||
|
|||||||
Reference in New Issue
Block a user