Files
narratio/internal/config/effective_pipeline.go

94 lines
2.8 KiB
Go

package config
import (
"fmt"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
)
// EffectivePipelineRootPath reports the absolute root pipeline path retained
// while resolving cfg. It is empty for a pipeline not loaded through the
// production loader.
func EffectivePipelineRootPath(cfg *PipelineConfig) string {
if cfg == nil || cfg.resolution == nil {
return ""
}
return cfg.resolution.rootPath
}
// EffectivePipelineImports reports the ordered, absolute import paths that
// contributed to cfg.
func EffectivePipelineImports(cfg *PipelineConfig) []string {
if cfg == nil || cfg.resolution == nil {
return nil
}
return append([]string(nil), cfg.resolution.imports...)
}
// NormalizedConfigurationPath returns a clean absolute path when possible for
// display-only configuration provenance.
func NormalizedConfigurationPath(path string) string {
return normalizedProvenancePath(path)
}
// EffectivePipelineValueRecord identifies one normalized, secret-free
// effective configuration value. Values use deterministic compact JSON
// representations so command output can be compared without raw YAML layout.
type EffectivePipelineValueRecord struct {
Path string
Value string
}
// EffectivePipelineValues projects a fully resolved pipeline into sorted
// logical configuration values. Mappings are flattened, while sequences remain
// atomic values. The projection uses the same normalized effective mapping as
// persistence and informational identity; it is not a native inspection view.
func EffectivePipelineValues(cfg *PipelineConfig) ([]EffectivePipelineValueRecord, error) {
if cfg == nil {
return nil, fmt.Errorf("pipeline config is required")
}
return projectionValueRecords(projectEffectivePipeline(cfg))
}
// MarshalEffectivePipeline materializes completed configuration for persistence.
// Credentials retain reference names; domain catalogs remain separate.
func MarshalEffectivePipeline(cfg *PipelineConfig) ([]byte, error) {
if cfg == nil {
return nil, fmt.Errorf("pipeline config is required")
}
canonical, err := projectionJSON(projectEffectivePipeline(cfg))
if err != nil {
return nil, err
}
var document yaml.Node
if err := yaml.Unmarshal(canonical, &document); err != nil {
return nil, fmt.Errorf("decode pipeline materialization: %w", err)
}
var blockStyle func(*yaml.Node)
blockStyle = func(node *yaml.Node) {
node.Style = 0
for _, child := range node.Content {
blockStyle(child)
}
}
blockStyle(&document)
output, err := yaml.Marshal(&document)
if err != nil {
return nil, fmt.Errorf("serialize effective pipeline: %w", err)
}
return output, nil
}
func normalizedProvenancePath(path string) string {
if strings.TrimSpace(path) == "" {
return ""
}
abs, err := filepath.Abs(path)
if err != nil {
return filepath.Clean(path)
}
return filepath.Clean(abs)
}