82 lines
3.4 KiB
Python
82 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.googlechat.auth import probe_account
|
|
from yuxi.channel.extensions.googlechat.types import ResolvedGoogleChatAccount
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class GoogleChatStatusAdapter:
|
|
async def probe(self, account_dict: dict) -> bool:
|
|
account = account_dict.get("resolved")
|
|
if not isinstance(account, ResolvedGoogleChatAccount):
|
|
return False
|
|
result = await probe_account(account)
|
|
return result.get("ok", False)
|
|
|
|
def build_summary(self, snapshot) -> dict:
|
|
return {
|
|
"channel": "googlechat",
|
|
"mode": "webhook",
|
|
}
|
|
|
|
def build_account_snapshot(self, account_dict: dict) -> dict:
|
|
return {
|
|
"account_id": account_dict.get("account_id", "default"),
|
|
"name": account_dict.get("name", ""),
|
|
"configured": account_dict.get("credential_source", "none") != "none",
|
|
"enabled": account_dict.get("enabled", True),
|
|
}
|
|
|
|
def collect_status_issues(self, accounts: list[dict]) -> list[dict]:
|
|
issues = []
|
|
for account in accounts:
|
|
if not account:
|
|
continue
|
|
|
|
if not account.get("audience"):
|
|
issues.append({
|
|
"channel": "googlechat",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "audience_missing",
|
|
"message": "Audience is not configured. Webhook token verification will fail.",
|
|
"fix": "Set channels.googlechat.audience and channels.googlechat.audienceType.",
|
|
})
|
|
|
|
if not account.get("audience_type"):
|
|
issues.append({
|
|
"channel": "googlechat",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "audience_type_missing",
|
|
"message": "audienceType is not configured.",
|
|
"fix": "Set channels.googlechat.audienceType to 'app-url' or 'project-number'.",
|
|
})
|
|
|
|
resolved = account.get("resolved")
|
|
if isinstance(resolved, ResolvedGoogleChatAccount):
|
|
if resolved.audience_type == "app-url" and not resolved.app_principal:
|
|
issues.append({
|
|
"channel": "googlechat",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "app_principal_missing",
|
|
"message": (
|
|
'appPrincipal is missing for audienceType "app-url"; '
|
|
"add-on token verification will fail. "
|
|
"Set appPrincipal to the numeric OAuth 2.0 client ID (uniqueId, 21 digits), not an email."
|
|
),
|
|
})
|
|
|
|
if resolved.app_principal and "@" in resolved.app_principal:
|
|
issues.append({
|
|
"channel": "googlechat",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "app_principal_is_email",
|
|
"message": (
|
|
f'appPrincipal "{resolved.app_principal}" looks like an email address. '
|
|
"Set appPrincipal to the numeric OAuth 2.0 client ID (uniqueId, 21 digits), not an email."
|
|
),
|
|
})
|
|
|
|
return issues |