MCPcopy Create free account
hub / github.com/AutoForgeAI/autoforge / _validate_pkill_processes

Function _validate_pkill_processes

security.py:514–548  ·  view source on GitHub ↗

Validate and normalize pkill_processes from a YAML config. Each entry must be a non-empty string matching VALID_PROCESS_NAME_PATTERN (alphanumeric, dots, underscores, hyphens only -- no regex metacharacters). Used by both load_org_config() and load_project_commands(). Args:

(config: dict, config_path: Path)

Source from the content-addressed store, hash-verified

512
513
514def _validate_pkill_processes(config: dict, config_path: Path) -> Optional[list[str]]:
515 """
516 Validate and normalize pkill_processes from a YAML config.
517
518 Each entry must be a non-empty string matching VALID_PROCESS_NAME_PATTERN
519 (alphanumeric, dots, underscores, hyphens only -- no regex metacharacters).
520 Used by both load_org_config() and load_project_commands().
521
522 Args:
523 config: Parsed YAML config dict that may contain 'pkill_processes'
524 config_path: Path to the config file (for log messages)
525
526 Returns:
527 Normalized list of process names, or None if validation fails.
528 Returns an empty list if 'pkill_processes' is not present.
529 """
530 if "pkill_processes" not in config:
531 return []
532
533 processes = config["pkill_processes"]
534 if not isinstance(processes, list):
535 logger.warning(f"Config at {config_path}: 'pkill_processes' must be a list")
536 return None
537
538 normalized = []
539 for i, proc in enumerate(processes):
540 if not isinstance(proc, str):
541 logger.warning(f"Config at {config_path}: pkill_processes[{i}] must be a string")
542 return None
543 proc = proc.strip()
544 if not proc or not VALID_PROCESS_NAME_PATTERN.fullmatch(proc):
545 logger.warning(f"Config at {config_path}: pkill_processes[{i}] has invalid value '{proc}'")
546 return None
547 normalized.append(proc)
548 return normalized
549
550
551def get_org_config_path() -> Path:

Callers 2

load_org_configFunction · 0.85
load_project_commandsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected