Allow remote detect in production until local Ollama is connected.
Keep KANSHO_ENV=production and require an explicit operator flag instead of treating Prod as Development. Promote to Prod only via merge commit on main. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dd7858347c
commit
af6fe55577
23 files changed
+236
-27
No files matched your search
+21
-2
@@ -26,7 +26,7 @@ def load_env_file(path: Path | None = None) -> None:
|
||||
|
||||
|
||||
def runtime_env() -> str:
|
||||
"""development/test may use remote plaintext detect. production must not."""
|
||||
"""development/test may use remote plaintext detect. production must not, unless overridden."""
|
||||
raw = (os.environ.get("KANSHO_ENV") or "").strip().lower()
|
||||
if raw in {"production", "prod"}:
|
||||
return "production"
|
||||
@@ -37,8 +37,27 @@ def runtime_env() -> str:
|
||||
return "development"
|
||||
|
||||
|
||||
def env_flag(name: str) -> bool:
|
||||
raw = (os.environ.get(name) or "").strip().lower()
|
||||
return raw in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def remote_plaintext_detect_reason() -> str:
|
||||
"""Why remote detect is allowed or blocked. Never logs secrets."""
|
||||
if runtime_env() != "production":
|
||||
return "non_production"
|
||||
if env_flag("KANSHO_ALLOW_REMOTE_DETECT"):
|
||||
return "operator_override"
|
||||
return "blocked"
|
||||
|
||||
|
||||
def allows_remote_plaintext_detect() -> bool:
|
||||
return runtime_env() != "production"
|
||||
"""Remote plaintext detect is default-off in production.
|
||||
|
||||
Endbetrieb remains local detect. Until Ollama is connected, an operator
|
||||
may set KANSHO_ALLOW_REMOTE_DETECT. That does not disable the gateway.
|
||||
"""
|
||||
return remote_plaintext_detect_reason() != "blocked"
|
||||
|
||||
|
||||
def upsert_env_value(name: str, value: str, path: Path | None = None) -> None:
|
||||
|
||||
Reference in new issue
Block a user