Refactor: Centralize command patterns in single source of truth
CRITICAL: Prevents inconsistent sudo/SSH patterns across codebase. Created command_patterns.py with: - Single source of truth for ALL command execution patterns - SSH key path constant: /var/lib/macha/.ssh/id_ed25519 - Remote user constant: macha - sudo prefix for all remote commands - Helper functions: build_ssh_command(), transform_ssh_command() - Self-validation tests Updated files to use centralized patterns: - tools.py: Uses transform_ssh_command() - remote_monitor.py: Uses build_ssh_command() - system_discovery.py: Uses build_ssh_command() - DESIGN.md: Documents centralized approach Benefits: - Impossible to have inconsistent patterns - Single place to update if needed - Self-documenting with validation tests - Prevents future refactoring errors DO NOT duplicate these patterns in other files - always import.
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
import subprocess
|
||||
from typing import Dict, Any, Optional
|
||||
from pathlib import Path
|
||||
from command_patterns import build_ssh_command
|
||||
|
||||
|
||||
class RemoteMonitor:
|
||||
@@ -36,16 +37,8 @@ class RemoteMonitor:
|
||||
(success, stdout, stderr)
|
||||
"""
|
||||
try:
|
||||
# Use explicit SSH key path from macha user's home directory
|
||||
ssh_key = "/var/lib/macha/.ssh/id_ed25519"
|
||||
ssh_cmd = [
|
||||
"ssh",
|
||||
"-i", ssh_key,
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "ConnectTimeout=10",
|
||||
self.ssh_target,
|
||||
command
|
||||
]
|
||||
# Use centralized command pattern - see command_patterns.py
|
||||
ssh_cmd = build_ssh_command(self.hostname, command, timeout)
|
||||
|
||||
result = subprocess.run(
|
||||
ssh_cmd,
|
||||
|
||||
Reference in New Issue
Block a user