Add namespace and collection inventories

This commit is contained in:
2026-10-17 06:25:14 +00:00
parent c9b623b374
commit 8669294cf6
9 changed files with 295 additions and 3 deletions

View File

@@ -127,6 +127,8 @@ type loaded struct {
backendIDs []string
profileIDs []string
promptIDs []domain.PromptIdentity
namespaces map[string][]string
collections []CollectionIdentity
}
type resourceBases struct {
@@ -266,9 +268,38 @@ func load(main configkit.Input, underlays []configkit.Underlay) (*loaded, error)
for _, id := range sortedKeys(state.prompts) {
state.promptIDs = append(state.promptIDs, domain.PromptIdentity{ID: id, Version: stringPointerValue(state.prompts[id].definition.Version)})
}
state.namespaces = map[string][]string{
"backend": resourceNamespaces(state.backendIDs),
"profile": resourceNamespaces(state.profileIDs),
"prompt": promptNamespaces(state.promptIDs),
}
for _, namespace := range sortedKeys(result.Config.Collections) {
collection := result.Config.Collections[namespace]
state.collections = append(state.collections, CollectionIdentity{
Namespace: namespace, ReleaseVersion: stringPointerValue(collection.ReleaseVersion),
})
}
return state, nil
}
func resourceNamespaces(ids []string) []string {
namespaces := make(map[string]struct{})
for _, id := range ids {
if namespace, _, qualified := strings.Cut(id, "/"); qualified {
namespaces[namespace] = struct{}{}
}
}
return sortedKeys(namespaces)
}
func promptNamespaces(prompts []domain.PromptIdentity) []string {
ids := make([]string, len(prompts))
for index := range prompts {
ids[index] = prompts[index].ID
}
return resourceNamespaces(ids)
}
func checkConfigurationVersion(version configkit.Version, validation *configkit.Validation) error {
if !version.Present {
return nil