106 lines
7.7 KiB
Go
106 lines
7.7 KiB
Go
package consoleauth
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||
"git.yuntuo.hk/k2safe/orbit/platform/auth"
|
||
)
|
||
|
||
// ApplicationEntry 是应用接入列表的一行;同一应用的不同命名空间分别展示。
|
||
type ApplicationEntry struct {
|
||
ApplicationID core.ID `json:"application_id"` // ApplicationID 所属应用标识。
|
||
Application string `json:"application"` // Application 应用名称。
|
||
NamespaceID core.ID `json:"namespace_id"` // NamespaceID 数据隔离范围标识。
|
||
Namespace string `json:"namespace"` // Namespace 命名空间名称。
|
||
Environment string `json:"environment"` // Environment 环境名称。
|
||
Enabled bool `json:"enabled"` // Enabled 应用与命名空间均启用时为真。
|
||
}
|
||
|
||
// ApplicationPage 按命名空间标识分页,每页最多 50 行,不包含秘密。
|
||
type ApplicationPage struct {
|
||
Items []ApplicationEntry `json:"items"` // Items 当前页接入范围。
|
||
Next core.ID `json:"next,omitempty"` // Next 下一页的排他起点。
|
||
}
|
||
|
||
// AccessQueue 是接入配置可选的队列。
|
||
type AccessQueue struct {
|
||
Paused bool `json:"paused"` // Paused 暂停执行,不能表示已退役。
|
||
RetiredAt *time.Time `json:"retired_at,omitempty"` // RetiredAt 永久退役时间,历史仍可查询。
|
||
ID core.ID `json:"id"` // ID 队列标识。
|
||
Name string `json:"name"` // Name 队列名称。
|
||
}
|
||
|
||
// AccessCredential 是脱敏的凭据元数据,绝不返回秘密或秘密摘要。
|
||
type AccessCredential struct {
|
||
TokenStored bool `json:"token_stored"` // TokenStored 当前 Token 是否已加密保存;列表不会返回秘密。
|
||
PreviousValidUntil *time.Time `json:"previous_valid_until,omitempty"` // PreviousValidUntil 上一代令牌实际截止,空表示无旧令牌。
|
||
ID core.ID `json:"id"` // ID 凭据标识,重新生成 Token 时不改变。
|
||
Name string `json:"name"` // Name 凭据名称。
|
||
Revision uint64 `json:"revision,string"` // Revision 轮换的并发校验版本。
|
||
ExpiresAt *time.Time `json:"expires_at,omitempty"` // ExpiresAt 到期时间,空表示无固定到期时间。
|
||
RevokedAt *time.Time `json:"revoked_at,omitempty"` // RevokedAt 撤销时间,非空时禁止轮换。
|
||
Permissions auth.Permissions `json:"permissions"` // Permissions 动作和队列授权范围。
|
||
}
|
||
|
||
// ApplicationDetail 展示一个命名空间的队列和凭据,读取量有界。
|
||
type ApplicationDetail struct {
|
||
ActiveSubscriptions uint64 `json:"active_subscriptions"` // ActiveSubscriptions 未退役订阅数量,包含暂停订阅。
|
||
SubscriptionLimit uint32 `json:"subscription_limit"` // SubscriptionLimit 命名空间活动订阅上限。
|
||
TokenVaultEnabled bool `json:"token_vault_enabled"` // TokenVaultEnabled 当前节点是否配置了凭据保管密钥。
|
||
Entry ApplicationEntry `json:"entry"` // Entry 当前应用与环境。
|
||
Queues []AccessQueue `json:"queues"` // Queues 最多 100 个队列。
|
||
Credentials []AccessCredential `json:"credentials"` // Credentials 最多 100 张凭据。
|
||
Truncated bool `json:"truncated"` // Truncated 为真时不得把当前结果解释为完整清单。
|
||
}
|
||
|
||
// ApplicationInput 描述创建应用或变更凭据的管理员意图。
|
||
type ApplicationInput struct {
|
||
Kind string `json:"kind"` // Kind CREATE、ROTATE、SET_EXPIRY 或 FINALIZE。
|
||
Application string `json:"application"` // Application 新应用名称,仅 CREATE 使用。
|
||
Namespace string `json:"namespace"` // Namespace 新命名空间名称,仅 CREATE 使用。
|
||
Environment string `json:"environment"` // Environment 新环境名称,仅 CREATE 使用。
|
||
Queue string `json:"queue"` // Queue 初始队列名称,仅 CREATE 使用。
|
||
Capabilities []string `json:"capabilities,omitempty"` // Capabilities 显式选择的业务权限组,仅 CREATE 使用。
|
||
NamespaceID core.ID `json:"namespace_id,omitempty"` // NamespaceID 轮换目标所属范围。
|
||
CredentialID core.ID `json:"credential_id,omitempty"` // CredentialID 轮换目标凭据。
|
||
ExpectedRevision uint64 `json:"expected_revision,string"` // ExpectedRevision 轮换时读取到的版本。
|
||
ValidDays int `json:"valid_days"` // ValidDays 有效天数;0 为长期,1–365 为定期。
|
||
GraceDays int `json:"grace_days,omitempty"` // GraceDays ROTATE 的旧令牌过渡天数,0–30;0 显式立即失效。
|
||
Reason string `json:"reason"` // Reason 写入审计的变更原因。
|
||
}
|
||
|
||
// ApplicationOperation 是浏览器在提交前保存的固定操作;启用保管时仅保存 Token 密文。
|
||
// 网络结果未知时重放同一份内容,禁止重新生成操作身份或秘密。
|
||
type ApplicationOperation struct {
|
||
Version int `json:"version,omitempty"` // Version v2 支持长期令牌与过渡;旧固定操作未设置时沿用 v1。
|
||
Input ApplicationInput `json:"input"` // Input 固定的管理员意图。
|
||
OperationID core.ID `json:"operation_id"` // OperationID 稳定幂等身份。
|
||
ApplicationID core.ID `json:"application_id"` // ApplicationID 新建或已核验的应用标识。
|
||
NamespaceID core.ID `json:"namespace_id"` // NamespaceID 固定命名空间标识。
|
||
QueueID core.ID `json:"queue_id,omitempty"` // QueueID 新建应用的初始队列。
|
||
CredentialID core.ID `json:"credential_id"` // CredentialID 固定凭据身份。
|
||
Token string `json:"token,omitempty"` // Token 当前秘密;服务端启用保管后加密保存,不能进入日志。
|
||
ExpiresAt *time.Time `json:"expires_at,omitempty"` // ExpiresAt 固定到期时间,空表示长期或不适用。
|
||
PreviousValidUntil *time.Time `json:"previous_valid_until,omitempty"` // PreviousValidUntil ROTATE 固定过渡截止。
|
||
}
|
||
|
||
// ApplicationReceipt 是数据库持久化的脱敏回执。
|
||
type ApplicationReceipt struct {
|
||
OperationID core.ID `json:"operation_id"` // OperationID 原操作身份。
|
||
ApplicationID core.ID `json:"application_id"` // ApplicationID 应用标识。
|
||
NamespaceID core.ID `json:"namespace_id"` // NamespaceID 命名空间标识。
|
||
CredentialID core.ID `json:"credential_id"` // CredentialID 凭据标识。
|
||
Revision uint64 `json:"revision,string"` // Revision 操作提交后的凭据版本。
|
||
Deduplicated bool `json:"deduplicated"` // Deduplicated 命中原回执,不代表当前 Token 仍有效。
|
||
}
|
||
|
||
// Applications 只面向部署指定的单管理员浏览器会话,不接收业务 SDK 身份。
|
||
type Applications interface {
|
||
ListApplications(context.Context, auth.Token, core.ID) (ApplicationPage, error)
|
||
GetApplication(context.Context, auth.Token, core.ID) (ApplicationDetail, error)
|
||
PrepareApplication(context.Context, auth.Token, ApplicationInput) (ApplicationOperation, error)
|
||
ApplyApplication(context.Context, auth.Token, ApplicationOperation) (ApplicationReceipt, error)
|
||
}
|