package config import ( "crypto/sha256" "encoding/hex" "fmt" ) const ( pipelineDefaultOwnershipSource = "default" effectivePipelineDigestVersion = "narratio-effective-pipeline-v3\n" ) // PipelineOverlayProvenance identifies the overlay selected while resolving a // pipeline. It contains only non-secret selection metadata. type PipelineOverlayProvenance struct { Name string Source string OverlayPath string } // SelectedPipelineOverlay reports the overlay used to resolve cfg, if any. func SelectedPipelineOverlay(cfg *PipelineConfig) (*PipelineOverlayProvenance, bool) { if cfg == nil || cfg.resolution == nil || cfg.resolution.selectedOverlay == nil { return nil, false } selection := cfg.resolution.selectedOverlay return &PipelineOverlayProvenance{Name: selection.name, Source: selection.source, OverlayPath: selection.overlayPath}, true } // EffectivePipelineDigest reports the deterministic secret-free digest for a // resolved pipeline. func EffectivePipelineDigest(cfg *PipelineConfig) string { if cfg == nil || cfg.resolution == nil { return "" } return cfg.resolution.effectiveDigest } func finalizePipelineResolution(cfg *PipelineConfig) error { if cfg == nil || cfg.resolution == nil { return fmt.Errorf("pipeline resolution metadata is required") } return recomputePipelineEffectiveDigest(cfg) } // recomputePipelineEffectiveDigest is the single package-owned hook for // refreshing provenance after later resolution expands concrete pipeline // values. Loader directives and runtime provenance are not serialized. func recomputePipelineEffectiveDigest(cfg *PipelineConfig) error { if cfg == nil || cfg.resolution == nil { return fmt.Errorf("pipeline resolution metadata is required") } canonical, err := projectionJSON(projectEffectivePipeline(cfg)) if err != nil { return err } digestInput := append([]byte(effectivePipelineDigestVersion), canonical...) digest := sha256.Sum256(digestInput) cfg.resolution.effectiveDigest = hex.EncodeToString(digest[:]) return nil }