1from __future__ import annotations
2
3from plain.preflight import PreflightCheck, PreflightResult, register_check
4from plain.runtime import settings
5
6
7@register_check(name="connect.secret_key")
8class CheckConnectSecretKey(PreflightCheck):
9 def run(self) -> list[PreflightResult]:
10 if str(settings.CONNECT_SECRET_KEY):
11 return []
12 if not settings.CONNECT_PAGEVIEWS_TOKEN:
13 return []
14 return [
15 PreflightResult(
16 fix=(
17 "CONNECT_PAGEVIEWS_TOKEN is set but CONNECT_SECRET_KEY is empty. "
18 "Get the shared secret from the App settings page on Plain Cloud "
19 "and set CONNECT_SECRET_KEY in app/settings.py (or the "
20 "PLAIN_CONNECT_SECRET_KEY env var), or unset the token."
21 ),
22 id="connect.secret_key_missing",
23 warning=True,
24 )
25 ]