Skip to content

Commit

Permalink
cloudapi: Add /distributions to cloudapi
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.
  • Loading branch information
bcl committed Sep 25, 2024
1 parent fa8f427 commit b669d56
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 833 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ require (
github.com/osbuild/images v0.87.0
github.com/osbuild/osbuild-composer/pkg/splunk_logger v0.0.0-20240814102216-0239db53236d
github.com/osbuild/pulp-client v0.1.0
github.com/prometheus/client_golang v1.20.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/segmentio/ksuid v1.0.4
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/proglottis/gpgme v0.1.3 h1:Crxx0oz4LKB3QXc5Ea0J19K/3ICfy3ftr5exgUK1AU0=
github.com/proglottis/gpgme v0.1.3/go.mod h1:fPbW/EZ0LvwQtH8Hy7eixhp1eF3G39dtx7GUN+0Gmy0=
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
Expand Down
36 changes: 36 additions & 0 deletions internal/cloudapi/v2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"os"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -1188,3 +1189,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)
}
435 changes: 258 additions & 177 deletions internal/cloudapi/v2/openapi.v2.gen.go

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions internal/cloudapi/v2/openapi.v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,28 @@ paths:
schema:
$ref: '#/components/schemas/Error'

/distributions:
get:
operationId: getDistributionList
summary: |-
Get all of the supported distribution repository details
security:
- Bearer: []
responses:
'200':
description: Distribution repositories
content:
application/json:
schema:
$ref: '#/components/schemas/DistributionList'
'500':
description: Unexpected error occurred
content:
application/json:
schema:
$ref: '#/components/schemas/Error'


/errors/{id}:
get:
operationId: getError
Expand Down Expand Up @@ -512,6 +534,21 @@ components:
items:
$ref: '#/components/schemas/Error'

DistributionList:
properties:
map:
type: object
additionalProperties:
map:
type: object
additionalProperties:
map:
type: object
additionalProperties:
type: array
items:
$ref: '#/components/schemas/BlueprintRepository'

ComposeStatus:
allOf:
- $ref: '#/components/schemas/ObjectReference'
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/prometheus/client_golang/NOTICE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b669d56

Please sign in to comment.