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 Oct 15, 2024
1 parent 6d0c175 commit f4fd7ec
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 184 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ require (
github.com/osbuild/images v0.88.0
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d
github.com/osbuild/pulp-client v0.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.2
github.com/segmentio/ksuid v1.0.4
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -192,7 +193,6 @@ require (
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/ostreedev/ostree-go v0.0.0-20210805093236-719684c64e4f // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/proglottis/gpgme v0.1.3 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
Expand Down
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 f4fd7ec

Please sign in to comment.