92 文件全量代码审查后的高危/中危修复,每条都带回归测试,并在未修复的 HEAD 上
反向确认过「测试确实会失败」。
- H1 域名同步整批失败:NormalizedDomain.expiry_date 契约声明为字符串,Cloudflare
适配器把 Registrar 的 ISO 时间戳截成 "YYYY-MM-DD" 直接赋给 Date 列,写库抛
TypeError;而 _sync_domains 的 commit 在循环外,一个域名就让整批全量回滚
(Cloudflare 域名实际从未同步成功)。现统一契约:base.py 新增 parse_iso_date,
适配器产出 date,_sync_domains 写库前再归一一次以兼容仍返回字符串的适配器
- M9 Vultr / DigitalOcean 的域名到期日此前完全没映射,这两家域名永远进不了续费提醒
- M1 同步失败变 500:能力分支写库失败后未回滚,Session 停在 pending-rollback,
随后更新 last_synced_at 的 commit 抛 PendingRollbackError,真实错误被 500 掩盖
- H2 AI 资产挂靠迁移静默零命中:迁移 SQL 用枚举值 'ai_agent' 匹配 Enum 列,而
SQLAlchemy Enum 存的是成员名 'AI_AGENT',该分支从未生效(6 个 AI 资产的
account_id 全为 NULL)。改用成员名并加日志留痕;账号命名沿用步骤 1 的
「{slug}-默认」约定,避免建出与既有账号语义重复、且没有凭证的空账号
(dry-run 实测:deepseek 资产复用已有且有凭证的 deepseek-默认)
- H3 2FA 动态码不刷新:otpState 全局常驻、收起只清 timer 不删条目,「不存在才拉」
的守卫导致再次展开显示上一次的旧码且倒计时冻结在 0。改为每次展开都重取;
stopOtp 同时清空旧码(避免重展开瞬间闪过已失效的码),并加请求代号,防止
「请求在途时收起」后返回的响应又重启轮询
- M10 账号弹窗关闭不清理:外层用 v-if 关闭并不卸载组件,onUnmounted 不触发,
OTP 轮询定时器与明文密码驻留后台。关闭时显式调 closePwd
- M2 提醒发不出去:Telegram 用 parse_mode=HTML,资产名含 < > & 时整条消息被 400
拒收;纯文本提醒不需要任何标签,去掉 parse_mode,并把拒收正文带回便于排查
- M3 负数天文案:cbb32ea 已修好提醒消息正文,本次补齐仍在直出负数的两处
(check_renewals.py 输出、设置页预览),后端抽出 renewal_service.day_text 统一,
前端走 Fmt.countdownText
验证:pytest 94 passed(新增 tests/test_domain_expiry.py、tests/test_notification.py);
本地起服务对 H2 迁移做真实 dry-run(6 个 AI 资产挂到 4 个账号、无重复账号、幂等、
非 AI 资产零影响,迁移前已备份);浏览器端以 otpState 状态断言验证 H3/M10,
设置页续费预览确认已过期项显示「已过期 N 天」。
106 lines
3.7 KiB
Python
106 lines
3.7 KiB
Python
"""Vultr 适配器(REST API v2,Bearer Token)
|
||
|
||
API 文档:https://www.vultr.com/api/
|
||
所需配置:{"api_key": "..."}
|
||
"""
|
||
|
||
import httpx
|
||
|
||
from app.adapters.base import (
|
||
AccountInfo,
|
||
BaseAdapter,
|
||
NormalizedDomain,
|
||
NormalizedVPS,
|
||
parse_iso_date,
|
||
)
|
||
from app.adapters.registry import register
|
||
|
||
|
||
@register("vultr-api")
|
||
class VultrAdapter(BaseAdapter):
|
||
required_config = ["api_key"]
|
||
BASE = "https://api.vultr.com/v2"
|
||
|
||
def _headers(self) -> dict:
|
||
return {"Authorization": f"Bearer {self.config.get('api_key', '')}"}
|
||
|
||
def _get(self, path: str) -> dict:
|
||
with httpx.Client(timeout=30) as client:
|
||
resp = client.get(self.BASE + path, headers=self._headers())
|
||
resp.raise_for_status()
|
||
return resp.json()
|
||
|
||
def test_connection(self) -> dict:
|
||
try:
|
||
data = self._get("/account")
|
||
balance = data.get("account", {}).get("balance")
|
||
return {"ok": True, "message": f"连接成功,账户余额 {balance} USD"}
|
||
except httpx.HTTPStatusError as e:
|
||
return {"ok": False, "message": f"HTTP {e.response.status_code}:API Key 无效或权限不足"}
|
||
except Exception as e: # noqa: BLE001
|
||
return {"ok": False, "message": str(e)}
|
||
|
||
def get_account(self) -> AccountInfo:
|
||
acc = self._get("/account").get("account", {})
|
||
return AccountInfo(
|
||
balance=acc.get("balance"),
|
||
currency="USD",
|
||
pending_charges=acc.get("pending_charges"),
|
||
raw=acc,
|
||
)
|
||
|
||
def list_vps(self) -> list:
|
||
result = []
|
||
cursor = ""
|
||
while True:
|
||
path = "/instances?per_page=100"
|
||
if cursor:
|
||
path += f"&cursor={cursor}"
|
||
data = self._get(path)
|
||
for inst in data.get("instances", []):
|
||
ram_mb = inst.get("ram") or 0
|
||
result.append(
|
||
NormalizedVPS(
|
||
external_id=inst.get("id"),
|
||
name=inst.get("label") or inst.get("id"),
|
||
ip_address=inst.get("main_ip"),
|
||
region=inst.get("region"),
|
||
os=inst.get("os"),
|
||
cpu_cores=inst.get("vcpu_count"),
|
||
memory_gb=round(ram_mb / 1024, 1) if ram_mb else None,
|
||
disk_gb=inst.get("disk"),
|
||
status="active" if inst.get("status") == "active" else (inst.get("status") or "unknown"),
|
||
monthly_cost=inst.get("monthly_cost"),
|
||
currency="USD",
|
||
raw=inst,
|
||
)
|
||
)
|
||
cursor = data.get("meta", {}).get("links", {}).get("next") or ""
|
||
if not cursor:
|
||
break
|
||
return result
|
||
|
||
def list_domains(self) -> list:
|
||
result = []
|
||
cursor = ""
|
||
while True:
|
||
path = "/domains?per_page=100"
|
||
if cursor:
|
||
path += f"&cursor={cursor}"
|
||
data = self._get(path)
|
||
for d in data.get("domains", []):
|
||
result.append(
|
||
NormalizedDomain(
|
||
external_id=d.get("domain"),
|
||
domain_name=d.get("domain"),
|
||
registrar="vultr",
|
||
# 非 Vultr 注册的域名 expiry_date 为空,解析失败统一归为 None
|
||
expiry_date=parse_iso_date(d.get("expiry_date")),
|
||
raw=d,
|
||
)
|
||
)
|
||
cursor = data.get("meta", {}).get("links", {}).get("next") or ""
|
||
if not cursor:
|
||
break
|
||
return result
|