import re _INSTANCE_NAME_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$") def validate_instance_name(raw: str) -> str: if not _INSTANCE_NAME_RE.fullmatch(raw): raise ValueError( "instance name must match [a-z0-9][a-z0-9_-]{0,63}" ) return raw def validate_overlay_ref(raw: str) -> str: if raw != raw.strip(): raise ValueError("overlay ref must not have leading or trailing whitespace") if not raw: raise ValueError("overlay ref must not be empty") if "\\" in raw: raise ValueError("overlay ref must use forward slashes") if raw.startswith("/"): raise ValueError("overlay ref must be relative") if any(component in {"", ".", ".."} for component in raw.split("/")): raise ValueError("overlay ref must not contain empty, current, or parent components") return raw