Check API connectivity, validate API key and client version, and return the user email.
(codeplainAPI: codeplain_api.CodeplainAPI)
| 141 | |
| 142 | |
| 143 | def _check_connection(codeplainAPI: codeplain_api.CodeplainAPI) -> Optional[str]: |
| 144 | """Check API connectivity, validate API key and client version, and return the user email.""" |
| 145 | response = codeplainAPI.connection_check(system_config.client_version) |
| 146 | |
| 147 | if not response.get("api_key_valid", False): |
| 148 | raise InvalidAPIKey( |
| 149 | "The provided API key is invalid. Please provide a valid API key using the CODEPLAIN_API_KEY environment variable " |
| 150 | "or the --api-key argument.\n" |
| 151 | ) |
| 152 | |
| 153 | if not response.get("client_version_valid", False): |
| 154 | min_version = response.get("min_client_version", "unknown") |
| 155 | raise OutdatedClientVersion( |
| 156 | "Outdated client version: " |
| 157 | f"Your client version ({system_config.client_version}) is outdated. Minimum required version is {min_version}. " |
| 158 | "Please update using: uv tool upgrade codeplain" |
| 159 | ) |
| 160 | |
| 161 | return response.get("user_email") |
| 162 | |
| 163 | |
| 164 | def warn_if_acceptance_tests_without_conformance_script(plain_module, args) -> None: |
no test coverage detected