Files

50 lines
2.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package httpapi
import "net/http"
const integrationAPIDocs = `# Sea vHost 管理端对接 API v1
管理端“对接 API”签发密钥。请求头:Authorization: Bearer <token>。
不使用浏览器登录 Cookie。所有请求与返回均为 JSON。
GET /api/integration/v1/users(users:read)
GET /api/integration/v1/hosts(hosts:read)
POST /api/integration/v1/users(users:write)
POST /api/integration/v1/hosts(hosts:write)
GET /api/integration/v1/tasks/{id}(tasks:read)
GET /api/integration/v1/tasks/{id}/download(credentials:read)
写入必须带 Idempotency-Key: <8–128 字节的唯一标识>。相同密钥和标识重试返回原任务;数据不同返回 409。
POST 返回 202 {"batch":{"id":123,...}};主控后台执行,可轮询 tasks/{id}。
任务仅能由提交该任务的 API 密钥读取。吊销、过期后无法调用,队列剩余条目停止;已开始的操作会完成并保存结果。
请求示例:
{"operation":"create_users","rows":[{"slug":"customer01","name":"客户一","email":"user@example.com"}]}
{"operation":"create_hosts","rows":[{"name":"站点一","tenantId":123,"nodeId":1,"planId":1,"runtime":"PHP","version":"8.4","runPath":"/public","autoSSL":false}]}
密码留空独立随机生成。tenantId 为 0 时不绑定用户,仍可使用独立主机账号。
用户操作:create_users / user_enable / user_disable。
主机操作:create_hosts / assign_hosts / host_subscription / host_start / host_stop / host_password_reset。
批量最多:用户 100;主机创建 50;管理 200。
管理 rows 使用 hostId,建议包含查询返回的 ownershipVersion,避免误操作已转移主机。
assign_hosts: tenantId(0 解绑)、credentialMode(preserve/reset)、stopServices(默认 true)。
host_subscription: planId、setExpiry:true、expiresAt(RFC3339 或 null,null 为长期)。
user_enable/user_disable: accountId 为用户归属账号编号。
所有操作拒绝任意宝塔 API、系统路径或 shell 命令。
下载为 sea-vhost.batch-result v1 JSON;凭据结果仅保留 24 小时。
回调不包含密码或输入,仅有批次状态与成功/失败计数。
回调请求:POST HTTPS 地址(443),禁止内网与保留地址,禁止重定向。
X-Sea-Event: 唯一事件 ID;X-Sea-Timestamp: Unix 秒;
X-Sea-Signature: sha256=<HMAC-SHA256 十六进制>。
签名内容:timestamp + "." + eventId + "." + 原始 JSON 字节。
使用创建时显示的独立 webhookSecret,验证时间偏差不超过 5 分钟,以事件 ID 去重。
回调有至少一次投递语义;返回 2xx 确认。重试间隔 1/2/4/8/16/32/64 分钟,总计最多 8 次。
吊销或过期后停止投递。`
func integrationDocs(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
_, _ = w.Write([]byte(integrationAPIDocs))
}