Migrate application configuration to the new ConfigKit API
This commit is contained in:
@@ -9,9 +9,9 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func runConfigEffective(args []string, stdout, stderr io.Writer, opts Options) int {
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func loadConfigKit(configPath, overlay string, overrides []configkit.Override, opts Options) (*config.LoadedConfig, string, error) {
|
||||
@@ -23,7 +23,7 @@ func loadConfigKit(configPath, overlay string, overrides []configkit.Override, o
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return loaded, path, nil
|
||||
return loaded, loaded.MainSourcePath(), nil
|
||||
}
|
||||
|
||||
func writeConfigLoadError(output io.Writer, err error) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestConfigLoadDiagnosticsIdentifyComposedSources(t *testing.T) {
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/buildinfo"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/artifacts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/config"
|
||||
@@ -27,6 +26,7 @@ import (
|
||||
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
|
||||
frameworkllm "gitea.maximumdirect.net/eric/notarius/internal/framework/llm"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
const defaultConfigPath = "/usr/local/etc/notarius/config.yml"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package config
|
||||
|
||||
import configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
import configkit "go.maximumdirect.net/configkit"
|
||||
|
||||
// documentNormalizer records leaf provenance and, while visiting a sequence,
|
||||
// covers its atomic mutation boundary. ConfigKit audits sequences as whole
|
||||
@@ -18,9 +18,9 @@ func (n documentNormalizer) inSequence(path configkit.Path) documentNormalizer {
|
||||
return n
|
||||
}
|
||||
|
||||
func (n documentNormalizer) Record(path configkit.Path, kind configkit.ChangeKind, reason string, dependencies ...configkit.Path) {
|
||||
n.Resolution.Record(path, kind, reason, dependencies...)
|
||||
func (n documentNormalizer) RecordNormalization(path configkit.Path, reason string, dependencies ...configkit.Path) {
|
||||
n.Resolution.RecordNormalization(path, reason, dependencies...)
|
||||
if n.sequence != nil {
|
||||
n.Resolution.Record(*n.sequence, kind, reason, append([]configkit.Path{path}, dependencies...)...)
|
||||
n.Resolution.RecordNormalization(*n.sequence, reason, append([]configkit.Path{path}, dependencies...)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package config
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func normalizeDocumentPaths(document *Document, context *configkit.Resolution, state *documentLoadState) {
|
||||
@@ -63,7 +63,7 @@ func initializeDocumentMainDirectory(resolution documentNormalizer, state *docum
|
||||
if state == nil || state.mainDirectory != "" {
|
||||
return
|
||||
}
|
||||
info, ok := resolution.InputInfo(configkit.Keys("version"))
|
||||
info, ok := resolution.EntryInfo(configkit.Keys("version"))
|
||||
if ok && len(info.Origin.Locations) == 1 {
|
||||
if source, sourceOK := resolution.Source(info.Origin.Locations[0].SourceID); sourceOK && source.Path != "" {
|
||||
state.mainDirectory = filepath.Dir(source.Path)
|
||||
@@ -102,7 +102,7 @@ func normalizeDocumentReferencePaths(references map[string]ReferenceDocument, pa
|
||||
} else {
|
||||
value := filepath.Clean(filepath.Join(base, *source.Path))
|
||||
if value != *source.Path {
|
||||
resolution.Record(sourcePath, configkit.ChangeNormalization, "resolved external reference path")
|
||||
resolution.RecordNormalization(sourcePath, "resolved external reference path")
|
||||
source.Path = documentValue(value)
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func documentPathBase(resolution documentNormalizer, state *documentLoadState, p
|
||||
if state != nil {
|
||||
original = state.originalPath(path)
|
||||
}
|
||||
info, ok := resolution.InputInfo(original)
|
||||
info, ok := resolution.EntryInfo(original)
|
||||
if !ok {
|
||||
if state != nil && state.mainDirectory != "" {
|
||||
return state.mainDirectory, true
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestDocumentPathsUseDeclaringFilesAcrossImports(t *testing.T) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestDocumentLoadAcceptsVersion5AndCanonicalShapes(t *testing.T) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestPipelineInheritancePreservesCompositionAndReplacesSteps(t *testing.T) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package config
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// LoadOptions contains configuration selections supplied by an application
|
||||
@@ -57,7 +57,7 @@ func documentDefinition(state *documentLoadState) configkit.Definition[Document]
|
||||
Path: configkit.Keys("version"),
|
||||
Check: validateDocumentVersion,
|
||||
},
|
||||
Secret: sensitiveDocumentPath,
|
||||
Sensitive: sensitiveDocumentPath,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// LoadedConfig keeps the finalized runtime configuration together with the
|
||||
@@ -59,6 +59,28 @@ func Load(path string, options LoadOptions) (*LoadedConfig, error) {
|
||||
return loadConfig(path, options)
|
||||
}
|
||||
|
||||
// LoadSource loads a selected source, including its imports, into an owned configuration.
|
||||
func LoadSource(source configkit.Source, options LoadOptions) (*LoadedConfig, error) {
|
||||
result, err := loadDocumentWithSource(source, options, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newLoadedConfig(result)
|
||||
}
|
||||
|
||||
// MainSourcePath returns the selected main file's recorded path, if any.
|
||||
func (loaded *LoadedConfig) MainSourcePath() string {
|
||||
if loaded == nil || loaded.result == nil {
|
||||
return ""
|
||||
}
|
||||
for _, source := range loaded.result.Sources() {
|
||||
if source.Layer == configkit.LayerMain && source.Kind == configkit.SourceKindFile && source.ImportedFrom == nil {
|
||||
return source.Path
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func loadConfigSource(source configkit.Source, options LoadOptions) (*LoadedConfig, error) {
|
||||
result, err := loadDocumentSource(source, options)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,16 +2,47 @@ package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
units "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/chunk/units"
|
||||
jsonoutput "gitea.maximumdirect.net/eric/notarius/internal/modules/generic/output/json"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestLoadSourceRetainsMainFileAndLoadsImports(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
main := filepath.Join(dir, "main.yml")
|
||||
fragment := filepath.Join(dir, "fragment.yml")
|
||||
if err := os.WriteFile(fragment, []byte("output:\n directory: imported-output\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(main, []byte("version: 5\nconfig:\n imports:\n - path: fragment.yml\n required: true\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := LoadSource(configkit.File(main), LoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := loaded.MainSourcePath(); got != main {
|
||||
t.Fatalf("main source path = %q, want %q", got, main)
|
||||
}
|
||||
if got := loaded.Config.Output.Directory; got != filepath.Join(dir, "imported-output") {
|
||||
t.Fatalf("imported output directory = %q", got)
|
||||
}
|
||||
bytesLoaded, err := loadConfigSource(configkit.Bytes("memory.yml", []byte("version: 5\n")), LoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := bytesLoaded.MainSourcePath(); got != "" {
|
||||
t.Fatalf("non-file main source path = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadedConfigConvertsDocumentsAndResolvesRuntimePipeline(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func resolveDocumentOperations(document *Document, resolution *configkit.Resolution, state *documentLoadState) error {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestWorkerKeyNormalizationPreservesExplicitCount(t *testing.T) {
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
// documentLoadState keeps the spelling supplied by the user while resolver
|
||||
@@ -255,7 +255,7 @@ func normalizeDocumentValue[T comparable](resolution documentNormalizer, path co
|
||||
return
|
||||
}
|
||||
if *target != value {
|
||||
resolution.Record(path, configkit.ChangeNormalization, reason)
|
||||
resolution.RecordNormalization(path, reason)
|
||||
*target = value
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func normalizePipelineDocumentString(resolution documentNormalizer, path configk
|
||||
}
|
||||
value := strings.TrimSpace(**target)
|
||||
if **target != value {
|
||||
resolution.Record(path, configkit.ChangeNormalization, reason)
|
||||
resolution.RecordNormalization(path, reason)
|
||||
**target = value
|
||||
}
|
||||
}
|
||||
@@ -312,7 +312,7 @@ func normalizeDocumentMap[T any](values map[string]T, path configkit.Path, kind
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
resolution.Record(path, configkit.ChangeNormalization, "normalized "+kind+" keys", dependencies...)
|
||||
resolution.RecordNormalization(path, "normalized "+kind+" keys", dependencies...)
|
||||
values = result
|
||||
}
|
||||
return values
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestDocumentRejectsExplicitInvalidBranches(t *testing.T) {
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func (e EffectiveConfig) RedactedResolvedPipelinePayload() pipeline.ResolvedPipeline {
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
configkit "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func TestValidationPolicyFileConfigurationIsStrictAndPresenceAware(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user