gateway_env.py 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. """Slack env -> gateway config bridge (``PlatformEntry.env_overrides``)."""
  2. from gateway.config import GatewayConfig, HomeChannel, Platform, PlatformConfig
  3. from gateway.platform_env import EnvCred, getenv
  4. def _home(config: GatewayConfig) -> None:
  5. """SLACK_HOME_CHANNEL creates a disabled Slack entry if needed; user_id/scope_id provenance survives an unchanged chat_id."""
  6. if not (slack_home := getenv("SLACK_HOME_CHANNEL")):
  7. return
  8. slack_config = config.platforms.setdefault(Platform.SLACK, PlatformConfig(enabled=False))
  9. existing_home = slack_config.home_channel
  10. same_home = existing_home is not None and existing_home.chat_id == slack_home
  11. slack_config.home_channel = HomeChannel(
  12. platform=Platform.SLACK, chat_id=slack_home,
  13. name=getenv("SLACK_HOME_CHANNEL_NAME"), thread_id=getenv("SLACK_HOME_CHANNEL_THREAD_ID") or None,
  14. user_id=existing_home.user_id if same_home else None,
  15. scope_id=existing_home.scope_id if same_home else None,
  16. )
  17. ENV_ENABLE_CREDENTIALS = ("SLACK_BOT_TOKEN",)
  18. ENV_OVERRIDES = (EnvCred(Platform.SLACK, ("SLACK_BOT_TOKEN",), token="SLACK_BOT_TOKEN"), _home)
  19. # Authorization env names (``PlatformEntry`` fields). Core reads them from this file when the
  20. # live entry lacks them: a user plugin overriding this platform, safe mode, the plugin disabled.
  21. AUTHZ = {
  22. "allowed_users_env": "SLACK_ALLOWED_USERS",
  23. "allow_all_env": "SLACK_ALLOW_ALL_USERS",
  24. "allow_bots_env": "SLACK_ALLOW_BOTS",
  25. "allowlist_suppresses_pairing": True,
  26. }