diff --git a/confsync/detectors/misc.py b/confsync/detectors/misc.py new file mode 100644 index 0000000..849cb4a --- /dev/null +++ b/confsync/detectors/misc.py @@ -0,0 +1,98 @@ +"""Miscellaneous configuration file detectors.""" + +from pathlib import Path +from typing import List, TYPE_CHECKING + +from confsync.detectors.base import BaseDetector, detector +from confsync.models.config_models import ConfigCategory + +if TYPE_CHECKING: + from confsync.models.config_models import ConfigFile + + +@detector +class SSHCDetector(BaseDetector): + """Detector for SSH configurations.""" + + category = ConfigCategory.SSH + tool_name = "ssh" + + def get_default_locations(self) -> List[str]: + """Get SSH config locations.""" + return [ + str(Path.home() / ".ssh"), + ] + + def get_file_patterns(self) -> List[str]: + """Get SSH file patterns.""" + return ["config", "known_hosts", "authorized_keys"] + + def detect(self) -> List["ConfigFile"]: + """Detect SSH configuration files.""" + configs = [] + home = Path.home() + + ssh_dir = home / ".ssh" + if ssh_dir.exists() and ssh_dir.is_dir(): + + ssh_files = [ + ssh_dir / "config", + ssh_dir / "known_hosts", + ssh_dir / "authorized_keys", + ] + + sensitive_patterns = ["id_rsa", "id_ed25519", "id_ecdsa", "id_dsa", "known_hosts.old"] + + for ssh_file in ssh_files: + if ssh_file.exists() and ssh_file.name not in sensitive_patterns: + config = self._create_config_file(str(ssh_file)) + config.metadata = {"ssh": "config", "sensitive": ssh_file.name == "config"} + if ssh_file.name == "config": + config.content = "[detected SSH config - content redacted for safety]" + configs.append(config) + + return configs + + +@detector +class DockerDetector(BaseDetector): + """Detector for Docker configurations.""" + + category = ConfigCategory.DOCKER + tool_name = "docker" + + def get_default_locations(self) -> List[str]: + """Get Docker config locations.""" + return [ + str(Path.home() / ".docker"), + str(Path.home() / ".config" / "docker"), + ] + + def get_file_patterns(self) -> List[str]: + """Get Docker file patterns.""" + return ["config.json", "daemon.json", "Dockerfile", ".dockerignore"] + + def detect(self) -> List["ConfigFile"]: + """Detect Docker configuration files.""" + configs = [] + home = Path.home() + + docker_dirs = [ + home / ".docker", + home / ".config" / "docker", + ] + + for docker_dir in docker_dirs: + if docker_dir.exists() and docker_dir.is_dir(): + docker_files = [ + docker_dir / "config.json", + docker_dir / "daemon.json", + ] + + for docker_file in docker_files: + if docker_file.exists(): + config = self._create_config_file(str(docker_file)) + config.metadata = {"container": "docker"} + configs.append(config) + + return configs