Add ConfigKit version 5 document boundary
This commit is contained in:
60
internal/core/config/load.go
Normal file
60
internal/core/config/load.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
)
|
||||
|
||||
// LoadOptions contains configuration selections supplied by an application
|
||||
// boundary. It is intentionally narrow: configuration discovery and CLI flag
|
||||
// parsing remain outside this package.
|
||||
type LoadOptions struct {
|
||||
Profile string
|
||||
Overrides []configkit.Override
|
||||
}
|
||||
|
||||
// loadDocument is the private ConfigKit load boundary under construction.
|
||||
// Production commands continue to use the existing version 4 loader until the
|
||||
// runtime conversion and command wiring are complete.
|
||||
func loadDocument(path string, options LoadOptions) (*configkit.Result[Document], error) {
|
||||
return loadDocumentSource(configkit.File(path), options)
|
||||
}
|
||||
|
||||
func loadDocumentSource(source configkit.Source, options LoadOptions) (*configkit.Result[Document], error) {
|
||||
return configkit.Load(source, configkit.Options[Document]{
|
||||
Definition: documentDefinition(),
|
||||
Profile: options.Profile,
|
||||
Overrides: options.Overrides,
|
||||
})
|
||||
}
|
||||
|
||||
func documentDefinition() configkit.Definition[Document] {
|
||||
return configkit.Definition[Document]{
|
||||
Defaults: func() Document {
|
||||
return Document{
|
||||
Pipelines: map[string]PipelineDocument{},
|
||||
Concurrency: &ConcurrencyDocument{
|
||||
StageWorkers: map[string]int{},
|
||||
},
|
||||
}
|
||||
},
|
||||
Version: &configkit.VersionRule{
|
||||
Path: configkit.Keys("version"),
|
||||
Check: validateDocumentVersion,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func validateDocumentVersion(version configkit.Version, validation *configkit.Validation) error {
|
||||
if !version.Present || version.Null {
|
||||
validation.Error(configkit.Keys("version"), "configuration version is required")
|
||||
return nil
|
||||
}
|
||||
if version.Text == "4" {
|
||||
validation.Error(configkit.Keys("version"), "configuration version 4 is no longer supported; migrate to version 5")
|
||||
return nil
|
||||
}
|
||||
if version.Text != "5" {
|
||||
validation.Error(configkit.Keys("version"), "unsupported configuration version")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user