Preserve composite ConfigKit provenance
This commit is contained in:
@@ -20,7 +20,6 @@ type pipelineResolutionMetadata struct {
|
||||
logicalNotariusConfig string
|
||||
logicalNotariusWorking string
|
||||
logicalNotariusCaptured bool
|
||||
ownership []pipelineFieldOwnership
|
||||
artifactFamilies map[string]ScriptoriumArtifactFamilyConfig
|
||||
artifactFamiliesExpanded bool
|
||||
configkitMetadata configkit.Metadata
|
||||
@@ -33,11 +32,6 @@ type pipelineOverlaySelection struct {
|
||||
overlayPath string
|
||||
}
|
||||
|
||||
type pipelineFieldOwnership struct {
|
||||
path string
|
||||
sources []string
|
||||
}
|
||||
|
||||
func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*PipelineConfig, error) {
|
||||
overlay := selectedPipelineOverlayName(opts)
|
||||
result, err := loadPipelineConfigKitResult(path, overlay)
|
||||
@@ -45,11 +39,7 @@ func loadPipelineWithConfigKit(path string, opts PipelineLoadOptions) (*Pipeline
|
||||
return nil, describePipelineLoadError(err)
|
||||
}
|
||||
cfg := result.Config
|
||||
metadata, err := pipelineMetadataFromConfigKit(&cfg, result, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load pipeline config: %w", err)
|
||||
}
|
||||
cfg.resolution = metadata
|
||||
cfg.resolution = pipelineMetadataFromConfigKit(result, opts)
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
@@ -257,19 +247,16 @@ func validatePipelineConfigKit(cfg *PipelineConfig, validation *configkit.Valida
|
||||
}
|
||||
}
|
||||
|
||||
func pipelineMetadataFromConfigKit(cfg *PipelineConfig, result *configkit.Result[PipelineConfig], opts PipelineLoadOptions) (*pipelineResolutionMetadata, error) {
|
||||
func pipelineMetadataFromConfigKit(result *configkit.Result[PipelineConfig], opts PipelineLoadOptions) *pipelineResolutionMetadata {
|
||||
sources := result.Sources()
|
||||
metadata := result.Metadata()
|
||||
resolved := &pipelineResolutionMetadata{
|
||||
configkitMetadata: metadata, configkitSources: sources,
|
||||
configkitMetadata: result.Metadata(), configkitSources: sources,
|
||||
}
|
||||
pathsByID := make(map[string]string, len(sources))
|
||||
for index, source := range sources {
|
||||
path := source.Path
|
||||
if path == "" {
|
||||
path = source.Label
|
||||
}
|
||||
pathsByID[source.ID] = path
|
||||
resolved.sources = append(resolved.sources, path)
|
||||
if index == 0 {
|
||||
resolved.rootPath = path
|
||||
@@ -280,19 +267,7 @@ func pipelineMetadataFromConfigKit(cfg *PipelineConfig, result *configkit.Result
|
||||
resolved.selectedOverlay = &pipelineOverlaySelection{name: selectedPipelineOverlayName(opts), source: "explicit", overlayPath: path}
|
||||
}
|
||||
}
|
||||
detailed, err := pipelineMetadataPaths(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, value := range detailed {
|
||||
info, ok := metadata.Lookup(configkit.Keys(value.segments...))
|
||||
sourceNames := []string{pipelineDefaultOwnershipSource}
|
||||
if ok {
|
||||
sourceNames = ownershipSources(info.Origin, pathsByID)
|
||||
}
|
||||
resolved.ownership = append(resolved.ownership, pipelineFieldOwnership{path: value.record.Path, sources: sourceNames})
|
||||
}
|
||||
return resolved, nil
|
||||
return resolved
|
||||
}
|
||||
|
||||
func pipelineMetadataPaths(cfg *PipelineConfig) ([]projectedPipelineValue, error) {
|
||||
@@ -300,14 +275,21 @@ func pipelineMetadataPaths(cfg *PipelineConfig) ([]projectedPipelineValue, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cfg.Scriptorium == nil || len(cfg.Scriptorium.ArtifactFamilies) == 0 {
|
||||
if cfg.Scriptorium == nil {
|
||||
return effective, nil
|
||||
}
|
||||
families, err := projectionDetailedRecords(map[string]any{"scriptorium": map[string]any{"artifact_families": cfg.Scriptorium.ArtifactFamilies}})
|
||||
families := cfg.Scriptorium.ArtifactFamilies
|
||||
if cfg.resolution != nil && len(cfg.resolution.artifactFamilies) != 0 {
|
||||
families = cfg.resolution.artifactFamilies
|
||||
}
|
||||
if len(families) == 0 {
|
||||
return effective, nil
|
||||
}
|
||||
detailedFamilies, err := projectionDetailedRecords(map[string]any{"scriptorium": map[string]any{"artifact_families": families}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(effective, families...), nil
|
||||
return append(effective, detailedFamilies...), nil
|
||||
}
|
||||
|
||||
func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []string {
|
||||
@@ -319,7 +301,7 @@ func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []st
|
||||
}
|
||||
seen := map[string]struct{}{}
|
||||
var sources []string
|
||||
for _, location := range origin.Locations {
|
||||
add := func(location configkit.Location) {
|
||||
value := pathsByID[location.SourceID]
|
||||
if value == "" {
|
||||
value = location.SourceID
|
||||
@@ -329,12 +311,35 @@ func ownershipSources(origin configkit.Origin, pathsByID map[string]string) []st
|
||||
sources = append(sources, value)
|
||||
}
|
||||
}
|
||||
for _, location := range origin.Locations {
|
||||
add(location)
|
||||
}
|
||||
for _, inheritance := range origin.Inheritance {
|
||||
for _, location := range inheritance.Locations {
|
||||
add(location)
|
||||
}
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
return []string{pipelineDefaultOwnershipSource}
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
func pipelineSourcePaths(cfg *PipelineConfig) map[string]string {
|
||||
paths := make(map[string]string)
|
||||
if cfg == nil || cfg.resolution == nil {
|
||||
return paths
|
||||
}
|
||||
for _, source := range cfg.resolution.configkitSources {
|
||||
path := source.Path
|
||||
if path == "" {
|
||||
path = source.Label
|
||||
}
|
||||
paths[source.ID] = path
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
func intPtr(value int) *int { return &value }
|
||||
func float64Ptr(value float64) *float64 { return &value }
|
||||
func boolPtr(value bool) *bool { return &value }
|
||||
|
||||
Reference in New Issue
Block a user