4528a55e6a
为什么:T6a 需要一张批次/差异表、全量只读扫描、R1-R8 判定和 finding 级处置;现有解析监控只转述台账状态,无法回答库内是否一致。 做什么:迁移 000084(upload_md5、runs/findings/actions、共享 removal_candidates 视图);WeKnora 字段与 1000/页扫描;runtime 只读客户端(0400 Key、503 降级);扫描/矩阵/动作/定时/僵死回收;9 条接口与 RBAC;overview 队列与删两张常量卡。 边界:只对测试库;对账零写请求;R1/R2 单条确认;R6 复用 /removal;R2 只管理员;生产链路未改。 验证:make verify 全绿(17 项);新增矩阵/扫描 R1-R8/零写/失败整批/动作/运行时/密钥权限测试。
303 lines
7.5 KiB
Go
303 lines
7.5 KiB
Go
package governance
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type SourceType string
|
|
|
|
const (
|
|
SourceTypePP SourceType = "pp"
|
|
SourceTypeAList SourceType = "alist"
|
|
SourceTypeDingTalk SourceType = "dingtalk"
|
|
SourceTypeManual SourceType = "manual"
|
|
)
|
|
|
|
func (sourceType SourceType) Valid() bool {
|
|
switch sourceType {
|
|
case SourceTypePP, SourceTypeAList, SourceTypeDingTalk, SourceTypeManual:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type ItemType string
|
|
|
|
const (
|
|
ItemTypeDocument ItemType = "document"
|
|
ItemTypeFile ItemType = "file"
|
|
ItemTypeLink ItemType = "link"
|
|
ItemTypeVideo ItemType = "video"
|
|
)
|
|
|
|
type Visibility string
|
|
|
|
const (
|
|
VisibilityInternal Visibility = "internal"
|
|
VisibilityExternal Visibility = "external"
|
|
VisibilityBoth Visibility = "both"
|
|
VisibilityBlocked Visibility = "blocked"
|
|
)
|
|
|
|
type VisibilityOrigin string
|
|
|
|
const (
|
|
VisibilityOriginPPPublicTag VisibilityOrigin = "pp_public_tag"
|
|
VisibilityOriginConfiguredScope VisibilityOrigin = "configured_scope"
|
|
VisibilityOriginManual VisibilityOrigin = "manual"
|
|
)
|
|
|
|
type SourceChange string
|
|
|
|
const (
|
|
SourceChangeUnchanged SourceChange = "unchanged"
|
|
SourceChangeAdded SourceChange = "added"
|
|
SourceChangeUpdated SourceChange = "updated"
|
|
SourceChangeDeleted SourceChange = "deleted"
|
|
SourceChangeUnavailable SourceChange = "unavailable"
|
|
)
|
|
|
|
func (state SourceChange) Valid() bool {
|
|
switch state {
|
|
case SourceChangeUnchanged, SourceChangeAdded, SourceChangeUpdated, SourceChangeDeleted, SourceChangeUnavailable:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type ReviewState string
|
|
|
|
const (
|
|
ReviewPending ReviewState = "pending"
|
|
ReviewApproved ReviewState = "approved"
|
|
ReviewRejected ReviewState = "rejected"
|
|
ReviewNotRequired ReviewState = "not_required"
|
|
)
|
|
|
|
func (state ReviewState) Valid() bool {
|
|
switch state {
|
|
case ReviewPending, ReviewApproved, ReviewRejected, ReviewNotRequired:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type ContentState string
|
|
|
|
const (
|
|
ContentUnknown ContentState = "unknown"
|
|
ContentDownloading ContentState = "downloading"
|
|
ContentVerified ContentState = "verified"
|
|
ContentInvalid ContentState = "invalid"
|
|
ContentOverLimit ContentState = "over_limit"
|
|
ContentFailed ContentState = "failed"
|
|
)
|
|
|
|
func (state ContentState) Valid() bool {
|
|
switch state {
|
|
case ContentUnknown, ContentDownloading, ContentVerified, ContentInvalid, ContentOverLimit, ContentFailed:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type IngestState string
|
|
|
|
const (
|
|
IngestPending IngestState = "pending"
|
|
IngestUploading IngestState = "uploading"
|
|
IngestUploaded IngestState = "uploaded"
|
|
IngestFailed IngestState = "failed"
|
|
)
|
|
|
|
func (state IngestState) Valid() bool {
|
|
switch state {
|
|
case IngestPending, IngestUploading, IngestUploaded, IngestFailed:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type ProcessingState string
|
|
|
|
const (
|
|
ProcessingPending ProcessingState = "pending"
|
|
ProcessingProcessing ProcessingState = "processing"
|
|
ProcessingFinalizing ProcessingState = "finalizing"
|
|
ProcessingCompleted ProcessingState = "completed"
|
|
ProcessingFailed ProcessingState = "failed"
|
|
ProcessingStalled ProcessingState = "stalled"
|
|
// ProcessingCancelled is the operator's "stop trying" decision on a
|
|
// permanently failing document (e.g. an empty DingTalk export). The
|
|
// publication leaves the attention lane; source data is untouched.
|
|
ProcessingCancelled ProcessingState = "cancelled"
|
|
)
|
|
|
|
// NormalizeWeKnoraParseStatus is the single upstream-to-platform vocabulary
|
|
// whitelist shared by polling and reconciliation. Unknown values are rejected
|
|
// instead of being collapsed into an "other" bucket: a new upstream state must
|
|
// be added deliberately.
|
|
func NormalizeWeKnoraParseStatus(status string) (string, bool) {
|
|
switch status {
|
|
case "pending", "processing", "finalizing", "completed", "failed", "cancelled", "deleting":
|
|
return status, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
func (state ProcessingState) Valid() bool {
|
|
switch state {
|
|
case ProcessingPending, ProcessingProcessing, ProcessingFinalizing, ProcessingCompleted, ProcessingFailed, ProcessingStalled, ProcessingCancelled:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type RetrievalState string
|
|
|
|
const (
|
|
RetrievalUnpublished RetrievalState = "unpublished"
|
|
RetrievalEnabled RetrievalState = "enabled"
|
|
RetrievalDisabling RetrievalState = "disabling"
|
|
RetrievalDisabled RetrievalState = "disabled"
|
|
RetrievalEnabling RetrievalState = "enabling"
|
|
RetrievalFailed RetrievalState = "failed"
|
|
)
|
|
|
|
func (state RetrievalState) Valid() bool {
|
|
switch state {
|
|
case RetrievalUnpublished, RetrievalEnabled, RetrievalDisabling, RetrievalDisabled, RetrievalEnabling, RetrievalFailed:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
type AcceptanceState string
|
|
|
|
const (
|
|
AcceptancePending AcceptanceState = "pending"
|
|
AcceptancePassed AcceptanceState = "passed"
|
|
AcceptanceFailed AcceptanceState = "failed"
|
|
AcceptanceManualRequired AcceptanceState = "manual_required"
|
|
)
|
|
|
|
func (state AcceptanceState) Valid() bool {
|
|
switch state {
|
|
case AcceptancePending, AcceptancePassed, AcceptanceFailed, AcceptanceManualRequired:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func ValidSHA256(value string) bool {
|
|
if len(value) != 64 {
|
|
return false
|
|
}
|
|
for _, character := range value {
|
|
if !((character >= '0' && character <= '9') || (character >= 'a' && character <= 'f')) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
type SourceConnection struct {
|
|
ID string
|
|
Type SourceType
|
|
Name string
|
|
BaseURL string
|
|
SecretRef string
|
|
Enabled bool
|
|
Schedule json.RawMessage
|
|
LastHealth json.RawMessage
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type SourceItem struct {
|
|
ID string
|
|
SourceConnectionID string
|
|
StableExternalID string
|
|
CanonicalURIHash string
|
|
ParentExternalID string
|
|
NormalizedPath string
|
|
Title string
|
|
ItemType ItemType
|
|
SizeBytes *int64
|
|
MIME string
|
|
Revision string
|
|
UpdatedAtSource *time.Time
|
|
Visibility Visibility
|
|
VisibilityOrigin VisibilityOrigin
|
|
LastSeenScanID string
|
|
SourceChange SourceChange
|
|
AbsenceStreak int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type ContentObject struct {
|
|
ID string
|
|
SHA256 string
|
|
SizeBytes int64
|
|
MIME string
|
|
ValidatedFormat string
|
|
LocalSpoolRef string
|
|
State ContentState
|
|
FirstDiscoveredAt time.Time
|
|
LastDiscoveredAt time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type SourceItemVersion struct {
|
|
ID string
|
|
SourceItemID string
|
|
Revision string
|
|
ContentObjectID *string
|
|
ContentState ContentState
|
|
DownloadError string
|
|
RawRecordSummary json.RawMessage
|
|
SourceUpdatedAt *time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type Publication struct {
|
|
ID string
|
|
SourceItemVersionID string
|
|
TestKBID string
|
|
KnowledgeID string
|
|
IngestState IngestState
|
|
ProcessingState ProcessingState
|
|
RetrievalState RetrievalState
|
|
ParserGeneration string
|
|
IndexGeneration string
|
|
LastError string
|
|
RetryCount int
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type AcceptanceResult struct {
|
|
ID string
|
|
PublicationID string
|
|
RunID string
|
|
CheckType string
|
|
State AcceptanceState
|
|
PolicyVersion string
|
|
EvidenceSummary json.RawMessage
|
|
ObservedAt time.Time
|
|
CreatedAt time.Time
|
|
}
|