feat: deliver client activation credentials and upgrade guidance
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -40,6 +40,7 @@ type integrationKitResponse struct {
|
||||
Prompt string `json:"prompt"`
|
||||
TestVector kitVector `json:"payload_example"`
|
||||
Protocol string `json:"protocol"`
|
||||
Upgrade string `json:"upgrade"`
|
||||
}
|
||||
|
||||
type kitAPI struct {
|
||||
@@ -73,6 +74,7 @@ func integrationKitInput(c *gin.Context) (string, string, bool) {
|
||||
func buildIntegrationKit(language, mode string) integrationKitResponse {
|
||||
label, modeLabel := integrationLanguages[language], integrationModes[mode]
|
||||
protocol, _ := integrationAsset("protocol.md")
|
||||
upgrade, _ := integrationAsset("upgrade.md")
|
||||
return integrationKitResponse{
|
||||
ProtocolVersion: "license-v2 / lease-v2",
|
||||
PlatformBaseURL: defaultIntegrationBaseURL,
|
||||
@@ -94,7 +96,8 @@ func buildIntegrationKit(language, mode string) integrationKitResponse {
|
||||
"403/409 进入不可用或人工处理状态;429 遵循 Retry-After;不得无限自动重试。",
|
||||
},
|
||||
Protocol: string(protocol),
|
||||
Prompt: integrationPrompt(label, modeLabel) + "\n\n" + languageRequirements(language) + "\n\n必须阅读接入包 protocol.md 与 openapi.json。签名规范化不是 JSON:固定顺序 key=value、LF 连接、UTF-8、无末尾换行;签名是 DER ECDSA 的无填充标准 Base64。先通过包内随机测试公钥的 license-v2 和 lease-v2 验签向量,再连接部署环境。测试公钥不得在生产中信任。",
|
||||
Upgrade: string(upgrade),
|
||||
Prompt: integrationPrompt(label, modeLabel) + "\n\n" + languageRequirements(language) + "\n\n必须阅读接入包 protocol.md、upgrade.md 与 openapi.json。签名规范化不是 JSON:固定顺序 key=value、LF 连接、UTF-8、无末尾换行;签名是 DER ECDSA 的无填充标准 Base64。先通过包内随机测试公钥的 license-v2 和 lease-v2 验签向量,再连接部署环境。测试公钥不得在生产中信任。\n\n客户端升级:当前仅可复用已授权发布包下载,尚未实现客户端版本检查或签名升级清单。先按 upgrade.md 的第一阶段完成受控人工升级;自动升级必须等待第二阶段升级元数据、独立发布信任根和灰度策略落地。",
|
||||
TestVector: kitVector{
|
||||
Version: "lease-v2", InstanceID: "11111111-2222-3333-4444-555555555555", State: "active",
|
||||
ServerTime: "2026-10-09T03:00:00Z", EntitlementExpiresAt: "2027-10-09T03:00:00Z", LeaseExpiresAt: "2026-10-23T03:00:00Z",
|
||||
@@ -115,6 +118,8 @@ func integrationPrompt(language, mode string) string {
|
||||
|
||||
默认授权平台根地址:%s。将它作为 SDK 的默认值,同时允许部署通过 LICENSE_API_BASE_URL 覆盖;配置为根地址,不要附加 /api/v1,不要在业务代码中散落硬编码 URL。
|
||||
|
||||
首次设置由管理员在“授权 → 实例 → 创建实例并获取激活凭据”交付 instance_id、license_key、secret。UI 字段统一为“实例 ID”“授权码”“激活密钥”。实例 ID 不是数据库数字 ID;授权码是后台授权密钥;secret 仅首次展示但持续用于心跳和下载。公钥通过受控渠道预置,管理员密码与私钥绝不能要求最终用户输入。已激活后从受保护存储恢复,不要每次启动重新填写。当前每条授权只绑定一个实例,丢失 secret 没有找回接口。
|
||||
|
||||
实现激活 POST /api/v1/activation/instances/{instance_id},提交 license_key、secret 和 Idempotency-Key;实现心跳 POST /api/v1/instances/{instance_id}/heartbeat,提交 secret、RFC3339 UTC client_time 和 Idempotency-Key。
|
||||
|
||||
必须使用受控渠道预置的 ECDSA P-256 公钥验证 license-v2 / lease-v2 信封,验证 key_id、version、instance_id、state、entitlement_expires_at、lease_expires_at。仅 active 且授权/租约均未过期时允许业务运行。持久化并原子更新已接受租约及本地、服务端时间高水位。secret 不得写入 URL、日志、异常、镜像或源码;403/409 停止自动重试,429 遵循 Retry-After。
|
||||
@@ -147,7 +152,7 @@ func (a *BusinessAPI) downloadIntegrationKit(c *gin.Context) {
|
||||
fmt.Fprintf(&b, "- %s\n", rule)
|
||||
}
|
||||
fmt.Fprintf(&b, "\n## 租约字段示例(不是签名测试向量)\n\n```json\n{\n \"version\": \"%s\",\n \"instance_id\": \"%s\",\n \"state\": \"%s\",\n \"server_time\": \"%s\",\n \"entitlement_expires_at\": \"%s\",\n \"lease_expires_at\": \"%s\"\n}\n```\n", kit.TestVector.Version, kit.TestVector.InstanceID, kit.TestVector.State, kit.TestVector.ServerTime, kit.TestVector.EntitlementExpiresAt, kit.TestVector.LeaseExpiresAt)
|
||||
fmt.Fprintf(&b, "\n\n%s\n", kit.Protocol)
|
||||
fmt.Fprintf(&b, "\n\n%s\n\n%s\n", kit.Protocol, kit.Upgrade)
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=license-platform-%s-%s-integration.md", language, mode))
|
||||
c.Data(http.StatusOK, "text/markdown; charset=utf-8", []byte(b.String()))
|
||||
|
||||
Reference in New Issue
Block a user