Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion gerrit_mcp_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,26 @@ def _normalize_gerrit_url(url: str, gerrit_hosts: List[Dict[str, Any]]) -> str:
return normalized_url


def _redact_command_for_logging(command: List[str]) -> List[str]:
"""Returns a copy of a curl command with credentials masked for logging."""
redacted = list(command)
for i, arg in enumerate(redacted):
if arg == "--user" and i + 1 < len(redacted):
user_part = redacted[i + 1].split(":", 1)[0]
redacted[i + 1] = f"{user_part}:***REDACTED***"
elif arg == "-b" and i + 1 < len(redacted):
redacted[i + 1] = "***REDACTED***"
return redacted


async def run_curl(args: List[str], gerrit_base_url: str) -> str:
"""Executes a curl command and returns the output."""
config = load_gerrit_config()
command = get_curl_command_for_gerrit_url(gerrit_base_url, config) + args
with open(LOG_FILE_PATH, "a") as log_file:
log_file.write(f"[gerrit-mcp-server] Executing: {" ".join(command)}\n")
log_file.write(
f"[gerrit-mcp-server] Executing: {' '.join(_redact_command_for_logging(command))}\n"
)

process = await asyncio.create_subprocess_exec(
*command,
Expand Down