75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
configkit "go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
const (
|
|
pipelineDefaultOwnershipSource = "default"
|
|
effectivePipelineDigestVersion = "narratio-effective-pipeline-v4\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")
|
|
}
|
|
snapshot, err := newPipelineInspection(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
canonical, err := projectionJSON(snapshot.Config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
digestInput := append([]byte(effectivePipelineDigestVersion), canonical...)
|
|
digest := sha256.Sum256(digestInput)
|
|
cfg.resolution.effectiveDigest = hex.EncodeToString(digest[:])
|
|
cfg.resolution.inspection = snapshot
|
|
return nil
|
|
}
|
|
|
|
func newPipelineInspection(cfg *PipelineConfig) (*configkit.Result[effectivePipelineProjection], error) {
|
|
projection := projectEffectivePipeline(cfg)
|
|
return configkit.Load(configkit.NoSource(), configkit.Options[effectivePipelineProjection]{Definition: configkit.Definition[effectivePipelineProjection]{Defaults: func() effectivePipelineProjection { return projection }}})
|
|
}
|