cloudapi: Add /distributions to return distro:arch:image-type

This adds support for listing all of the supported distributions,
their arches, the image types, and their repository details.

This returns 3 nested json objects. The keys for the first layer are the
distribution names. The 2nd layer's keys are the architectures supported
by that distribution, and the 3rd layer's keys are the image types
supported by that distribution:architecture pair. The value of the 3rd
layer is the repository information.

Resolves: RHEL-60133
This commit is contained in:
Brian C. Lane 2024-09-25 17:07:25 -07:00 committed by Brian C. Lane
parent 4b9f1a4956
commit 44ac65b70c
4 changed files with 355 additions and 197 deletions

View file

@ -1479,3 +1479,38 @@ func (h *apiHandlers) PostSearchPackages(ctx echo.Context) error {
Packages: packageListToPackageDetails(packages),
})
}
// GetDistributionList returns the list of all supported distribution repositories
// It is arranged by distro name -> architecture -> image type
func (h *apiHandlers) GetDistributionList(ctx echo.Context) error {
distros := make(map[string]map[string]map[string][]rpmmd.RepoConfig)
distroNames := h.server.repos.ListDistros()
sort.Strings(distroNames)
for _, distroName := range distroNames {
distro := h.server.distros.GetDistro(distroName)
if distro == nil {
continue
}
for _, archName := range distro.ListArches() {
arch, _ := distro.GetArch(archName)
for _, imageType := range arch.ListImageTypes() {
repos, err := h.server.repos.ReposByImageTypeName(distroName, archName, imageType)
if err != nil {
continue
}
if _, ok := distros[distroName]; !ok {
distros[distroName] = make(map[string]map[string][]rpmmd.RepoConfig)
}
if _, ok := distros[distroName][archName]; !ok {
distros[distroName][archName] = make(map[string][]rpmmd.RepoConfig)
}
distros[distroName][archName][imageType] = repos
}
}
}
return ctx.JSON(http.StatusOK, distros)
}