69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package artifacts
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
|
)
|
|
|
|
type Candidate struct {
|
|
Index int `json:"index"`
|
|
ExtractorKey string `json:"extractor_key"`
|
|
ArtifactType string `json:"artifact_type"`
|
|
SchemaVersion string `json:"schema_version"`
|
|
Payload json.RawMessage `json:"payload"`
|
|
SourceRefs []source.SourceRef `json:"source_refs,omitempty"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
}
|
|
|
|
type Artifact struct {
|
|
ExtractorKey string `json:"extractor_key"`
|
|
ArtifactType string `json:"artifact_type"`
|
|
SchemaVersion string `json:"schema_version"`
|
|
Payload json.RawMessage `json:"payload"`
|
|
SourceRefs []source.SourceRef `json:"source_refs,omitempty"`
|
|
Metadata map[string]any `json:"metadata,omitempty"`
|
|
}
|
|
|
|
type RejectedArtifact struct {
|
|
Candidate Candidate `json:"candidate"`
|
|
ValidatorName string `json:"validator_name"`
|
|
ReasonCode string `json:"reason_code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type RunManifest struct {
|
|
RunID string `json:"run_id,omitempty"`
|
|
InputAdapter string `json:"input_adapter,omitempty"`
|
|
SourceDigests []string `json:"source_digests,omitempty"`
|
|
Extractors []string `json:"extractors,omitempty"`
|
|
SchemaVersion string `json:"schema_version,omitempty"`
|
|
ValidationStatus string `json:"validation_status,omitempty"`
|
|
StartedAt *time.Time `json:"started_at,omitempty"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
}
|
|
|
|
func ArtifactFromCandidate(candidate Candidate) Artifact {
|
|
return Artifact{
|
|
ExtractorKey: candidate.ExtractorKey,
|
|
ArtifactType: candidate.ArtifactType,
|
|
SchemaVersion: candidate.SchemaVersion,
|
|
Payload: append(json.RawMessage(nil), candidate.Payload...),
|
|
SourceRefs: append([]source.SourceRef(nil), candidate.SourceRefs...),
|
|
Metadata: copyMetadata(candidate.Metadata),
|
|
}
|
|
}
|
|
|
|
func copyMetadata(metadata map[string]any) map[string]any {
|
|
if len(metadata) == 0 {
|
|
return nil
|
|
}
|
|
|
|
copied := make(map[string]any, len(metadata))
|
|
for key, value := range metadata {
|
|
copied[key] = value
|
|
}
|
|
return copied
|
|
}
|