为什么:同步入口此前只会拒绝;授权、预备份、四类写入、验证与失败恢复都没有代码。
本轮把编排与授权实现出来,真实生产执行仍按授权闸口关闭。
- internal/libraryrelease:预备份 → 数据库/资源/索引/Wiki → 验证 → 失败恢复;
授权过期/目标不符/快照不符/参数变化在动生产前拒绝;恢复失败单独上报。
- 迁移 000067 library_release_authorizations(目标+快照+参数摘要+有效期,可撤销)。
- POST/GET /api/v1/library/authorizations 与 /{id}/revoke,仅管理员签发,5–1440 分钟。
- worker library.sync 接编排:先闸口再授权,阶段落库,只有编排成功才标成功。
- 生产目标适配器未配置时显式失败(不返回零值状态),预备份存储同。
- overview 返回授权状态,页面"生产保护与恢复"显示签发人与有效期。
- 验收矩阵区分"已实现·隔离测试通过"与"真实执行未授权"。
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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("生产预备份存储未配置(需要生产读取凭据与可独立恢复的备份目标)")
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package v071
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"knowledge-governance/internal/libraryrelease"
|
||||
)
|
||||
|
||||
// 未配置时必须显式失败:不能返回零值让上层误以为"生产当前状态为空"。
|
||||
func TestProductionLibraryTargetFailsClosedWhenUnconfigured(t *testing.T) {
|
||||
if _, err := NewProductionLibraryTarget("", ""); !errors.Is(err, ErrProductionTargetUnconfigured) {
|
||||
t.Fatalf("constructor must refuse empty configuration, got %v", err)
|
||||
}
|
||||
target, err := NewProductionLibraryTarget("http://prod.invalid", "/tmp/key")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = target.Current(context.Background()); !errors.Is(err, ErrProductionTargetUnconfigured) {
|
||||
t.Fatalf("Current must fail closed, got %v", err)
|
||||
}
|
||||
if err = target.Apply(context.Background(), libraryrelease.StageDatabase, "snap-1"); !errors.Is(err, ErrProductionTargetUnconfigured) {
|
||||
t.Fatalf("Apply must fail closed, got %v", err)
|
||||
}
|
||||
if err = target.Verify(context.Background(), libraryrelease.Expectation{}); !errors.Is(err, ErrProductionTargetUnconfigured) {
|
||||
t.Fatalf("Verify must fail closed, got %v", err)
|
||||
}
|
||||
if err = target.Restore(context.Background(), libraryrelease.BackupRef{}); !errors.Is(err, ErrProductionTargetUnconfigured) {
|
||||
t.Fatalf("Restore must fail closed, got %v", err)
|
||||
}
|
||||
if _, err = (ArchiveBackupStore{}).Prepare(context.Background(), "snap-1", libraryrelease.CurrentState{}); err == nil {
|
||||
t.Fatal("backup store must refuse until wired")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user