Validate API key format. Args: api_key: API key to validate min_length: Minimum key length Returns: Validated API key Raises: ConfigurationError: If API key is invalid
(api_key: str, min_length: int = 10)
| 53 | |
| 54 | |
| 55 | def validate_api_key(api_key: str, min_length: int = 10) -> str: |
| 56 | """ |
| 57 | Validate API key format. |
| 58 | |
| 59 | Args: |
| 60 | api_key: API key to validate |
| 61 | min_length: Minimum key length |
| 62 | |
| 63 | Returns: |
| 64 | Validated API key |
| 65 | |
| 66 | Raises: |
| 67 | ConfigurationError: If API key is invalid |
| 68 | """ |
| 69 | if not api_key or not api_key.strip(): |
| 70 | raise ConfigurationError("API key cannot be empty") |
| 71 | |
| 72 | api_key = api_key.strip() |
| 73 | |
| 74 | if len(api_key) < min_length: |
| 75 | raise ConfigurationError( |
| 76 | f"API key too short (minimum {min_length} characters)" |
| 77 | ) |
| 78 | |
| 79 | return api_key |
| 80 | |
| 81 | |
| 82 | def validate_model_name(model: str) -> str: |
no test coverage detected