36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class GoogleChatApprovalAuth:
|
|
channel_label = "Google Chat"
|
|
|
|
def resolve_approvers(self, cfg: dict, account_id: str) -> list[str]:
|
|
gc_config = cfg.get("channels", {}).get("googlechat", {}) if cfg else {}
|
|
allow_from = gc_config.get("dm", {}).get("allowFrom", [])
|
|
|
|
if not allow_from:
|
|
account_cfg = gc_config.get("accounts", {}).get(account_id, {})
|
|
allow_from = account_cfg.get("dm", {}).get("allowFrom", [])
|
|
else:
|
|
account_cfg = gc_config.get("accounts", {}).get(account_id, {})
|
|
account_allow_from = account_cfg.get("dm", {}).get("allowFrom", [])
|
|
if account_allow_from:
|
|
allow_from = account_allow_from
|
|
|
|
return [a for a in (self._normalize_approver_id(entry) for entry in allow_from) if a]
|
|
|
|
def _normalize_approver_id(self, value) -> str | None:
|
|
if not value:
|
|
return None
|
|
for prefix in ("googlechat:",):
|
|
if value.startswith(prefix):
|
|
value = value[len(prefix):]
|
|
if value.startswith("users/") and "@" in value:
|
|
return None
|
|
if value.startswith("users/"):
|
|
return value.lower()
|
|
return f"users/{value.lower()}" |