Files
knowledge-governance/internal/releaseadapter/v071/library_production_target.go
T
姚章浩 7b8cc0384b
build / build (push) Successful in 1m19s
feat(library): 生产发布授权与同步/恢复编排,worker 接线
为什么:同步入口此前只会拒绝;授权、预备份、四类写入、验证与失败恢复都没有代码。
本轮把编排与授权实现出来,真实生产执行仍按授权闸口关闭。

- internal/libraryrelease:预备份 → 数据库/资源/索引/Wiki → 验证 → 失败恢复;
  授权过期/目标不符/快照不符/参数变化在动生产前拒绝;恢复失败单独上报。
- 迁移 000067 library_release_authorizations(目标+快照+参数摘要+有效期,可撤销)。
- POST/GET /api/v1/library/authorizations 与 /{id}/revoke,仅管理员签发,5–1440 分钟。
- worker library.sync 接编排:先闸口再授权,阶段落库,只有编排成功才标成功。
- 生产目标适配器未配置时显式失败(不返回零值状态),预备份存储同。
- overview 返回授权状态,页面"生产保护与恢复"显示签发人与有效期。
- 验收矩阵区分"已实现·隔离测试通过"与"真实执行未授权"。
2026-10-28 15:11:27 +08:00

53 lines
2.1 KiB
Go

package v071
import (
"context"
"errors"
"knowledge-governance/internal/libraryrelease"
)
// ErrProductionTargetUnconfigured 表示生产读/写适配器还没接线。
// 这是一个**显式缺项**,不是"暂时跳过":没有它就无法读生产当前状态、
// 无法建预备份、也无法验证或恢复,所以整条生产链路必须拒绝执行。
var ErrProductionTargetUnconfigured = errors.New("生产目标适配器未配置(需要生产端点、只读凭据与写入适配)")
// ProductionLibraryTarget 是整库同步的生产目标实现占位。
//
// 为什么先不做"半套"实现:读生产当前状态、写四类数据、验证与恢复必须同时成立,
// 只实现其中一半会让链路看起来可用却无法回滚。接口在此固定,接线时只补实现。
type ProductionLibraryTarget struct {
BaseURL string
APIKeyFile string
}
func NewProductionLibraryTarget(baseURL, apiKeyFile string) (*ProductionLibraryTarget, error) {
if baseURL == "" || apiKeyFile == "" {
return nil, ErrProductionTargetUnconfigured
}
return &ProductionLibraryTarget{BaseURL: baseURL, APIKeyFile: apiKeyFile}, nil
}
func (t *ProductionLibraryTarget) Current(context.Context) (libraryrelease.CurrentState, error) {
return libraryrelease.CurrentState{}, ErrProductionTargetUnconfigured
}
func (t *ProductionLibraryTarget) Apply(context.Context, libraryrelease.Stage, string) error {
return ErrProductionTargetUnconfigured
}
func (t *ProductionLibraryTarget) Verify(context.Context, libraryrelease.Expectation) error {
return ErrProductionTargetUnconfigured
}
func (t *ProductionLibraryTarget) Restore(context.Context, libraryrelease.BackupRef) error {
return ErrProductionTargetUnconfigured
}
// ArchiveBackupStore 也还没接线:预备份必须读生产当前整库,同样的前置条件。
type ArchiveBackupStore struct{}
func (ArchiveBackupStore) Prepare(context.Context, string, libraryrelease.CurrentState) (libraryrelease.BackupRef, error) {
return libraryrelease.BackupRef{}, errors.New("生产预备份存储未配置(需要生产读取凭据与可独立恢复的备份目标)")
}