Skip to content

Commit

Permalink
cloudapi: Add /distributions to return distro:arch:image-type
Browse files Browse the repository at this point in the history
This adds support for listing all of the supported distributions,
their arches, the image types, and their repository details.

Resolves: RHEL-60133
  • Loading branch information
bcl committed Sep 26, 2024
1 parent cb0536b commit e022191
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 183 deletions.
35 changes: 35 additions & 0 deletions internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,3 +1354,38 @@ func uploadStatusFromJobStatus(js *worker.JobStatus, je *clienterrors.Error) Upl
}
return UploadStatusValueSuccess
}

// 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)
}
Loading

0 comments on commit e022191

Please sign in to comment.