Index and validate identified resources

This commit is contained in:
2026-11-02 03:55:28 +00:00
parent b7565affe5
commit 8e8f61f53f
4 changed files with 68 additions and 39 deletions

View File

@@ -194,8 +194,8 @@ func indexedResourceID(namespace, localKey string) string {
func indexedBackends(config *document) map[string]backendConfig {
backends := make(map[string]backendConfig)
for _, resources := range resourceSets(config) {
for localKey, definition := range resources.backends {
backends[indexedResourceID(resources.namespace, localKey)] = definition
for _, definition := range resources.backends {
backends[indexedResourceID(resources.namespace, definition.ID)] = definition
}
}
return backends
@@ -204,8 +204,8 @@ func indexedBackends(config *document) map[string]backendConfig {
func indexedProfiles(config *document) map[string]profileConfig {
profiles := make(map[string]profileConfig)
for _, resources := range resourceSets(config) {
for localKey, definition := range resources.profiles {
profiles[indexedResourceID(resources.namespace, localKey)] = definition
for _, definition := range resources.profiles {
profiles[indexedResourceID(resources.namespace, definition.ID)] = definition
}
}
return profiles
@@ -476,16 +476,15 @@ func validateEffective(config *document, validation *configkit.Validation) {
if resources.isCollection && !domain.IsValidResourceNamespace(resources.namespace) {
validation.Error(configkit.Keys("collections", resources.namespace), "collection namespace must be nonblank and contain no slash")
}
for localKey := range resources.backends {
backendIDs[indexedResourceID(resources.namespace, localKey)] = struct{}{}
for _, backend := range resources.backends {
backendIDs[indexedResourceID(resources.namespace, backend.ID)] = struct{}{}
}
}
for _, resources := range sets {
for _, id := range sortedKeys(resources.backends) {
backend := resources.backends[id]
base := resources.bases.backends.Key(id)
if !domain.IsValidLocalResourceKey(id) {
validation.Error(base, "backend key must be a nonblank local key without a slash")
for index, backend := range resources.backends {
base := resources.bases.backends.Index(index)
if !domain.IsValidLocalResourceKey(backend.ID) {
validation.Error(base.Key("id"), "backend ID must be a nonblank local key without a slash")
}
if backend.Endpoint == nil || *backend.Endpoint == "" {
validation.Error(base.Key("endpoint"), "endpoint is required")
@@ -526,11 +525,10 @@ func validateEffective(config *document, validation *configkit.Validation) {
}
}
}
for _, id := range sortedKeys(resources.profiles) {
profile := resources.profiles[id]
base := resources.bases.profiles.Key(id)
if !domain.IsValidLocalResourceKey(id) {
validation.Error(base, "profile key must be a nonblank local key without a slash")
for index, profile := range resources.profiles {
base := resources.bases.profiles.Index(index)
if !domain.IsValidLocalResourceKey(profile.ID) {
validation.Error(base.Key("id"), "profile ID must be a nonblank local key without a slash")
}
if profile.Backend != nil && *profile.Backend != "" {
if !domain.IsValidResourceID(*profile.Backend) {
@@ -564,11 +562,10 @@ func validateEffective(config *document, validation *configkit.Validation) {
}
validateExtraParams(profile.ExtraParams, base.Key("extra_params"), false, validation)
}
for _, id := range sortedKeys(resources.prompts) {
prompt := resources.prompts[id]
base := resources.bases.prompts.Key(id)
if !domain.IsValidLocalResourceKey(id) {
validation.Error(base, "prompt key must be a nonblank local key without a slash")
for index, prompt := range resources.prompts {
base := resources.bases.prompts.Index(index)
if !domain.IsValidLocalResourceKey(prompt.ID) {
validation.Error(base.Key("id"), "prompt ID must be a nonblank local key without a slash")
}
if prompt.DefaultProfile != nil && *prompt.DefaultProfile != "" && !domain.IsValidResourceID(*prompt.DefaultProfile) {
validation.Error(base.Key("default_profile"), "default profile reference is malformed")