Use explicit IDs in configuration source builders

This commit is contained in:
2026-11-02 04:01:01 +00:00
parent a6f4d67e15
commit fd6e9742a1
6 changed files with 136 additions and 42 deletions

View File

@@ -14,13 +14,15 @@ const BackendRakestrawHome = backend.RakestrawHomeID
// BackendLocal is a conventional ID for a caller-configured local backend.
const BackendLocal = "local"
// BackendConfig is a presence-aware convenience value for a keyed backend
// BackendConfig is a presence-aware convenience value for an identified backend
// definition. Nil pointer fields are omitted, while non-nil pointers preserve
// explicit zero or blank values. A nil ExtraParams map is omitted; a non-nil
// empty map supplies an empty mapping. A nil SmokeTests pointer is omitted; a
// non-nil pointer supplies a smoke_tests mapping. Use raw ConfigKit Mapping
// inputs for explicit null. BackendConfig has no stable JSON representation.
type BackendConfig struct {
// ID is the local backend identity within its resource list.
ID string
// Endpoint is the required absolute HTTP(S) base URL after all layers merge.
Endpoint *string
// APIKeyEnv optionally names an environment variable, not a credential.
@@ -71,15 +73,16 @@ type AuthenticationProbeConfig struct {
Endpoint *string
}
// BackendSource creates a labeled ConfigKit mapping from keyed backend values.
// BackendSource creates a labeled ConfigKit mapping containing backend records
// in caller order. IDs are explicit and duplicates are left for loading to reject.
// It encodes fields without validating them; NewEngine validates the final
// effective configuration after all selected source layers are combined.
// Mapping captures a copy of supported input values at creation; unsupported
// values fail when the source is loaded.
func BackendSource(label string, backends map[string]BackendConfig) configkit.Source {
definitions := make(map[string]any, len(backends))
for id, config := range backends {
fields := make(map[string]any)
func BackendSource(label string, backends []BackendConfig) configkit.Source {
definitions := make([]any, 0, len(backends))
for _, config := range backends {
fields := map[string]any{"id": config.ID}
if config.Endpoint != nil {
fields["endpoint"] = *config.Endpoint
}
@@ -119,7 +122,7 @@ func BackendSource(label string, backends map[string]BackendConfig) configkit.So
}
fields["smoke_tests"] = smokeTests
}
definitions[id] = fields
definitions = append(definitions, fields)
}
return configkit.Mapping(label, map[string]any{"backends": definitions})
}