feat(sdk): 支持编译截止授权模式与 OUTDATED 降级状态
- payload 新增 bc(编译截止 Unix 秒)/bcm(deny|degrade),结构校验拒绝负值与非法动作 - SDK 支持 WithBuildTime/WithBuildTimeUnix 与 ldflags BuildTime 注入;未提供构建时间时 fail-closed - degrade 模式进入 OUTDATED 状态,授权查询零值但进程继续运行;修复心跳/Proxy 续租覆盖该状态的隐患 - 缓存恢复路径同样执行截止判定;无截止的存量 license 行为不变 - 补充 license/sdk 单元测试与状态迁移回归用例
This commit is contained in:
9 files changed
+631
-30
No files matched your search
+17
-8
@@ -8,13 +8,15 @@ import (
|
||||
|
||||
// LicenseInfo 是只读授权摘要。
|
||||
type LicenseInfo struct {
|
||||
JTI string `json:"jti"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
TenantName string `json:"tenant_name,omitempty"`
|
||||
ProductKey string `json:"product_key"`
|
||||
LicenseType string `json:"license_type"`
|
||||
ExpiresAt int64 `json:"expires_at"` // 0=永久
|
||||
NotBefore int64 `json:"not_before"`
|
||||
JTI string `json:"jti"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
TenantName string `json:"tenant_name,omitempty"`
|
||||
ProductKey string `json:"product_key"`
|
||||
LicenseType string `json:"license_type"`
|
||||
ExpiresAt int64 `json:"expires_at"` // 0=永久
|
||||
NotBefore int64 `json:"not_before"`
|
||||
BuildCutoff int64 `json:"build_cutoff,omitempty"` // 0=不限制
|
||||
BuildCutoffAction string `json:"build_cutoff_action,omitempty"` // deny|degrade
|
||||
}
|
||||
|
||||
// usable 判断当前状态是否允许正常查询(ACTIVE/GRACE)。
|
||||
@@ -110,6 +112,8 @@ func (c *Client) Check(fid string) (bool, Reason) {
|
||||
return false, ReasonStateInvalid
|
||||
case StateUnverified:
|
||||
return false, ReasonStateUnverified
|
||||
case StateOutdated:
|
||||
return false, ReasonStateOutdated
|
||||
case StateActive:
|
||||
if _, ok := s.payload.Ent[fid]; !ok {
|
||||
return false, ReasonNotEntitled
|
||||
@@ -126,11 +130,16 @@ func (c *Client) Info() LicenseInfo {
|
||||
return LicenseInfo{}
|
||||
}
|
||||
p := s.payload
|
||||
return LicenseInfo{
|
||||
info := LicenseInfo{
|
||||
JTI: p.JTI, TenantID: p.TID, TenantName: p.TName,
|
||||
ProductKey: p.Prod, LicenseType: p.LT,
|
||||
ExpiresAt: p.EXP, NotBefore: p.NBF,
|
||||
BuildCutoff: p.BC,
|
||||
}
|
||||
if p.BC > 0 {
|
||||
info.BuildCutoffAction = p.EffectiveBuildCutoffAction()
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
// tierRank 返回档位序号(未知档位返回 -1,视为低于一切已知档位)。
|
||||
|
||||
Reference in new issue
Block a user