Files
workphone-sdk/sdk/app/models/integrations_admin.py

93 lines
2.3 KiB
Python

"""第三方接入管理领域模型。
这些模型只描述控制面数据,不携带生产密钥或设备运行态对象。
"""
from __future__ import annotations
from dataclasses import asdict, dataclass, field
from typing import Any, Dict, List, Optional
APP_STATUS_ACTIVE = "active"
APP_STATUS_SUSPENDED = "suspended"
APP_STATUS_REVOKED = "revoked"
@dataclass
class IntegrationApplication:
app_id: str
name: str
organization: str = ""
purpose: str = ""
owner: str = ""
contact: str = ""
environment: str = "sandbox"
callback_url: str = ""
status: str = APP_STATUS_ACTIVE
created_by: str = "system"
created_at: str = ""
credential_count: int = 0
# 租户是运行时授权的公司边界;旧数据缺省归入 default。
tenant_id: str = "default"
def to_dict(self) -> Dict[str, Any]:
return asdict(self)
@dataclass
class ClientCredential:
credential_id: str
app_id: str
prefix: str
secret_digest: str
status: str = "active"
created_at: str = ""
rotated_at: Optional[str] = None
last_used_at: Optional[str] = None
def to_dict(self) -> Dict[str, Any]:
data = asdict(self)
data.pop("secret_digest", None)
return data
@dataclass
class UsageRecord:
usage_id: str
app_id: str
grant_id: Optional[str]
credential_id: Optional[str]
interface_scope: str
device_id: Optional[str]
document_id: Optional[str]
result: str
status_code: int
latency_ms: float
bytes_in: int
bytes_out: int
source_ip: str
occurred_at: str
blocked_reason: Optional[str] = None
def to_dict(self) -> Dict[str, Any]:
return asdict(self)
def public_application_defaults() -> Dict[str, Any]:
"""返回新第三方的安全默认值,空设备集合始终表示零设备。"""
return {
"policy": "deny_all",
"interface_scopes": ["auth:probe", "integration:metadata"],
"device_ids": [],
"device_groups": [],
"document_ids": ["integration-overview"],
"allow_write": False,
"allow_wechat_read": False,
"allow_batch": False,
"allow_delete": False,
"allow_configure": False,
"allow_publish": False,
"allow_secret_management": False,
}