:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cronitor): tell a rejected api key apart from a missing scope (#120418)
Tom Owersa2b8ffc3f342
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/source.pyindex 31045b9895f3..db155abd7b14 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/source.py@@ -31,6 +31,15 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_)from products.warehouse_sources.backend.types import ExternalDataSourceType+# Cronitor answers an unknown key with a 401 and a real key without the probed scope with a 403.+_KEY_REJECTED_ERROR = (+ "Cronitor rejected your API key. Copy the full key from Settings → API keys in your Cronitor account, "+ "then try again."+)+_MISSING_MONITOR_SCOPE_ERROR = (+ "Your Cronitor API key is missing the monitor:read scope. Update the key's scopes in Cronitor, then reconnect."+)+@SourceRegistry.registerclass CronitorSource(ResumableSource[CronitorSourceConfig, CronitorResumeConfig]):@@ -129,8 +138,10 @@ Create an API key under **Settings → API keys** in your Cronitor account, andok, status_code = validate_cronitor_credentials(config.api_key)if ok:return True, None- if status_code in (401, 403):- return False, "Invalid Cronitor API key. Make sure the key has the monitor:read scope."+ if status_code == 401:+ return False, _KEY_REJECTED_ERROR+ if status_code == 403:+ return False, _MISSING_MONITOR_SCOPE_ERRORreturn False, "Could not connect to Cronitor with the provided API key"def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[CronitorResumeConfig]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/tests/test_cronitor_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/tests/test_cronitor_source.pyindex 28a9924687c0..0bed8d2016ca 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/tests/test_cronitor_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/cronitor/tests/test_cronitor_source.py@@ -17,8 +17,16 @@ class TestCronitorSource:"mock_return, expected_valid, expected_message",[((True, 200), True, None),- ((False, 401), False, "Invalid Cronitor API key. Make sure the key has the monitor:read scope."),- ((False, 403), False, "Invalid Cronitor API key. Make sure the key has the monitor:read scope."),+ (+ (False, 401),+ False,+ "Cronitor rejected your API key. Copy the full key from Settings → API keys in your Cronitor account, then try again.",+ ),+ (+ (False, 403),+ False,+ "Your Cronitor API key is missing the monitor:read scope. Update the key's scopes in Cronitor, then reconnect.",+ ),((False, None), False, "Could not connect to Cronitor with the provided API key"),],)