Add reference catalog selection to pipeline configuration
This commit is contained in:
@@ -37,23 +37,30 @@ func (cfg *Config) PublicationOutputs() []PublishOutputRule {
|
||||
return cfg.ArtifactCatalog.PublishOutputs
|
||||
}
|
||||
|
||||
// ReferenceCatalogConfig maps vocabulary selections to native source files.
|
||||
type ReferenceCatalogConfig struct {
|
||||
Settings map[string]string `yaml:"settings" json:"settings"`
|
||||
Systems map[string]string `yaml:"systems" json:"systems"`
|
||||
}
|
||||
|
||||
// PipelineConfig contains durable pipeline-level settings.
|
||||
type PipelineConfig struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
Campaigns CampaignsConfig `yaml:"campaigns" json:"campaigns"`
|
||||
Storage StorageConfig `yaml:"storage" json:"storage"`
|
||||
Spool SpoolConfig `yaml:"spool" json:"spool"`
|
||||
Cache CacheConfig `yaml:"cache" json:"cache"`
|
||||
Publish *PublishConfig `yaml:"publish" json:"publish"`
|
||||
WhisperX WhisperXConfig `yaml:"whisperx" json:"whisperx"`
|
||||
Seriatim SeriatimConfig `yaml:"seriatim" json:"seriatim"`
|
||||
Audita AuditaConfig `yaml:"audita" json:"audita"`
|
||||
Normalize *NormalizeConfig `yaml:"normalize" json:"normalize"`
|
||||
Trim *TrimConfig `yaml:"trim" json:"trim"`
|
||||
Render *RenderConfig `yaml:"render" json:"render"`
|
||||
Scriptorium *ScriptoriumConfig `yaml:"scriptorium" json:"scriptorium"`
|
||||
Notarius *NotariusConfig `yaml:"notarius" json:"notarius"`
|
||||
Notification NotificationConfig `yaml:"notification" json:"notification"`
|
||||
ReferenceCatalog ReferenceCatalogConfig `yaml:"reference_catalog" json:"reference_catalog"`
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
Campaigns CampaignsConfig `yaml:"campaigns" json:"campaigns"`
|
||||
Storage StorageConfig `yaml:"storage" json:"storage"`
|
||||
Spool SpoolConfig `yaml:"spool" json:"spool"`
|
||||
Cache CacheConfig `yaml:"cache" json:"cache"`
|
||||
Publish *PublishConfig `yaml:"publish" json:"publish"`
|
||||
WhisperX WhisperXConfig `yaml:"whisperx" json:"whisperx"`
|
||||
Seriatim SeriatimConfig `yaml:"seriatim" json:"seriatim"`
|
||||
Audita AuditaConfig `yaml:"audita" json:"audita"`
|
||||
Normalize *NormalizeConfig `yaml:"normalize" json:"normalize"`
|
||||
Trim *TrimConfig `yaml:"trim" json:"trim"`
|
||||
Render *RenderConfig `yaml:"render" json:"render"`
|
||||
Scriptorium *ScriptoriumConfig `yaml:"scriptorium" json:"scriptorium"`
|
||||
Notarius *NotariusConfig `yaml:"notarius" json:"notarius"`
|
||||
Notification NotificationConfig `yaml:"notification" json:"notification"`
|
||||
|
||||
resolution *pipelineResolutionMetadata `yaml:"-" json:"-"`
|
||||
}
|
||||
|
||||
@@ -8,21 +8,22 @@ import (
|
||||
// effectivePipelineProjection safely materializes configuration for persistence
|
||||
// and informational identity. Native results own inspection and comparison.
|
||||
type effectivePipelineProjection struct {
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
Campaigns CampaignsConfig `yaml:"campaigns" json:"campaigns"`
|
||||
Storage effectiveStorageConfig `yaml:"storage" json:"storage"`
|
||||
Spool SpoolConfig `yaml:"spool" json:"spool"`
|
||||
Cache CacheConfig `yaml:"cache" json:"cache"`
|
||||
Publish *PublishConfig `yaml:"publish" json:"publish"`
|
||||
WhisperX WhisperXConfig `yaml:"whisperx" json:"whisperx"`
|
||||
Seriatim SeriatimConfig `yaml:"seriatim" json:"seriatim"`
|
||||
Audita effectiveAuditaConfig `yaml:"audita" json:"audita"`
|
||||
Normalize *NormalizeConfig `yaml:"normalize" json:"normalize"`
|
||||
Trim *TrimConfig `yaml:"trim" json:"trim"`
|
||||
Render *RenderConfig `yaml:"render" json:"render"`
|
||||
Scriptorium *effectiveScriptoriumConfig `yaml:"scriptorium" json:"scriptorium"`
|
||||
Notarius *effectiveNotariusConfig `yaml:"notarius" json:"notarius"`
|
||||
Notification NotificationConfig `yaml:"notification" json:"notification"`
|
||||
ReferenceCatalog ReferenceCatalogConfig `yaml:"reference_catalog" json:"reference_catalog"`
|
||||
Workspace WorkspaceConfig `yaml:"workspace" json:"workspace"`
|
||||
Campaigns CampaignsConfig `yaml:"campaigns" json:"campaigns"`
|
||||
Storage effectiveStorageConfig `yaml:"storage" json:"storage"`
|
||||
Spool SpoolConfig `yaml:"spool" json:"spool"`
|
||||
Cache CacheConfig `yaml:"cache" json:"cache"`
|
||||
Publish *PublishConfig `yaml:"publish" json:"publish"`
|
||||
WhisperX WhisperXConfig `yaml:"whisperx" json:"whisperx"`
|
||||
Seriatim SeriatimConfig `yaml:"seriatim" json:"seriatim"`
|
||||
Audita effectiveAuditaConfig `yaml:"audita" json:"audita"`
|
||||
Normalize *NormalizeConfig `yaml:"normalize" json:"normalize"`
|
||||
Trim *TrimConfig `yaml:"trim" json:"trim"`
|
||||
Render *RenderConfig `yaml:"render" json:"render"`
|
||||
Scriptorium *effectiveScriptoriumConfig `yaml:"scriptorium" json:"scriptorium"`
|
||||
Notarius *effectiveNotariusConfig `yaml:"notarius" json:"notarius"`
|
||||
Notification NotificationConfig `yaml:"notification" json:"notification"`
|
||||
}
|
||||
|
||||
type effectiveStorageConfig struct {
|
||||
@@ -77,7 +78,8 @@ type effectiveScriptoriumConfig struct {
|
||||
|
||||
func projectEffectivePipeline(cfg *PipelineConfig) effectivePipelineProjection {
|
||||
projection := effectivePipelineProjection{
|
||||
Workspace: cfg.Workspace, Campaigns: cfg.Campaigns, Storage: effectiveStorageConfig{Backend: cfg.Storage.Backend},
|
||||
ReferenceCatalog: cfg.ReferenceCatalog,
|
||||
Workspace: cfg.Workspace, Campaigns: cfg.Campaigns, Storage: effectiveStorageConfig{Backend: cfg.Storage.Backend},
|
||||
Spool: cfg.Spool, Cache: cfg.Cache, Publish: cfg.Publish,
|
||||
WhisperX: cfg.WhisperX, Seriatim: cfg.Seriatim,
|
||||
Normalize: cfg.Normalize, Trim: cfg.Trim, Render: cfg.Render,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
@@ -119,6 +120,23 @@ func defaultPublishOutputs() []PublishOutputRule {
|
||||
}
|
||||
|
||||
func resolvePipelineConfig(cfg *PipelineConfig, resolution *configkit.Resolution, invocationDir string) error {
|
||||
for _, group := range []struct {
|
||||
name string
|
||||
entries map[string]string
|
||||
}{
|
||||
{"settings", cfg.ReferenceCatalog.Settings}, {"systems", cfg.ReferenceCatalog.Systems},
|
||||
} {
|
||||
ids := make([]string, 0, len(group.entries))
|
||||
for id := range group.entries {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
sort.Strings(ids)
|
||||
for _, id := range ids {
|
||||
value := group.entries[id]
|
||||
resolveHostResource(resolution, configkit.Keys("reference_catalog", group.name, id), &value, invocationDir)
|
||||
group.entries[id] = value
|
||||
}
|
||||
}
|
||||
resolveHostResource(resolution, configkit.Keys("workspace", "root"), &cfg.Workspace.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("campaigns", "root"), &cfg.Campaigns.Root, invocationDir)
|
||||
resolveHostResource(resolution, configkit.Keys("spool", "root"), &cfg.Spool.Root, invocationDir)
|
||||
|
||||
24
internal/config/reference_catalog.go
Normal file
24
internal/config/reference_catalog.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
|
||||
// SelectSetting returns the source for a selected setting, or no source for an omitted selection.
|
||||
func (catalog ReferenceCatalogConfig) SelectSetting(id string) (string, error) {
|
||||
return selectReference("setting", id, catalog.Settings)
|
||||
}
|
||||
|
||||
// SelectSystem returns the source for a selected system, or no source for an omitted selection.
|
||||
func (catalog ReferenceCatalogConfig) SelectSystem(id string) (string, error) {
|
||||
return selectReference("system", id, catalog.Systems)
|
||||
}
|
||||
|
||||
func selectReference(kind, id string, entries map[string]string) (string, error) {
|
||||
if id == "" {
|
||||
return "", nil
|
||||
}
|
||||
path, ok := entries[id]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unknown reference catalog %s %q", kind, id)
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
55
internal/config/reference_catalog_test.go
Normal file
55
internal/config/reference_catalog_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReferenceCatalogImportedOriginsAndSelections(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", `config:
|
||||
imports:
|
||||
- path: catalog/catalog.yml
|
||||
reference_catalog:
|
||||
settings:
|
||||
local: ./local.yml
|
||||
whisperx:
|
||||
transcribe_url: https://transcription.example.test/transcribe
|
||||
`)
|
||||
writePipelineFixture(t, dir, "catalog/catalog.yml", `reference_catalog:
|
||||
settings:
|
||||
sample: ./settings/sample.yml
|
||||
systems:
|
||||
sample: ./systems/sample.yml
|
||||
`)
|
||||
cfg, err := LoadPipeline(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct{ got, want string }{
|
||||
{cfg.ReferenceCatalog.Settings["sample"], filepath.Join(dir, "catalog/settings/sample.yml")},
|
||||
{cfg.ReferenceCatalog.Settings["local"], filepath.Join(dir, "local.yml")},
|
||||
{cfg.ReferenceCatalog.Systems["sample"], filepath.Join(dir, "catalog/systems/sample.yml")},
|
||||
} {
|
||||
if tc.got != tc.want {
|
||||
t.Fatalf("path %q, want %q", tc.got, tc.want)
|
||||
}
|
||||
}
|
||||
if got, err := cfg.ReferenceCatalog.SelectSetting("sample"); err != nil || got != cfg.ReferenceCatalog.Settings["sample"] {
|
||||
t.Fatalf("selection: %q, %v", got, err)
|
||||
}
|
||||
if _, err := cfg.ReferenceCatalog.SelectSystem("missing"); err == nil || !strings.Contains(err.Error(), "missing") {
|
||||
t.Fatalf("missing selection: %v", err)
|
||||
}
|
||||
if got, err := cfg.ReferenceCatalog.SelectSetting(""); err != nil || got != "" {
|
||||
t.Fatalf("omitted selection: %q, %v", got, err)
|
||||
}
|
||||
b, err := MarshalEffectivePipeline(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(b), "reference_catalog:") || !strings.Contains(string(b), "sample:") {
|
||||
t.Fatalf("catalog omitted from effective snapshot: %s", b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user