Validate and return *name*, or raise ``HTTPException(400)``. Suitable for REST endpoint handlers where FastAPI will convert the exception into an HTTP 400 response automatically. Args: name: Project name to validate. Returns: The validated project name (unchanged).
(name: str)
| 32 | |
| 33 | |
| 34 | def validate_project_name(name: str) -> str: |
| 35 | """Validate and return *name*, or raise ``HTTPException(400)``. |
| 36 | |
| 37 | Suitable for REST endpoint handlers where FastAPI will convert the |
| 38 | exception into an HTTP 400 response automatically. |
| 39 | |
| 40 | Args: |
| 41 | name: Project name to validate. |
| 42 | |
| 43 | Returns: |
| 44 | The validated project name (unchanged). |
| 45 | |
| 46 | Raises: |
| 47 | HTTPException: If *name* is invalid. |
| 48 | """ |
| 49 | if not _PROJECT_NAME_RE.match(name): |
| 50 | raise HTTPException( |
| 51 | status_code=400, |
| 52 | detail="Invalid project name. Use only letters, numbers, hyphens, and underscores (1-50 chars)." |
| 53 | ) |
| 54 | return name |