kojiapi: Add endpoint for retrieving job manifest
Add and implement an API endpoint that returns the manifests for a given osbuild-koji job. The route returns an array of manifests, one for each image in the request. Retrieves the arguments of each Build Job to extract the Manifest.
This commit is contained in:
parent
1c5f6810be
commit
7ec084fa56
3 changed files with 81 additions and 0 deletions
|
|
@ -87,6 +87,9 @@ type ServerInterface interface {
|
|||
// Get logs for a compose.
|
||||
// (GET /compose/{id}/logs)
|
||||
GetComposeIdLogs(ctx echo.Context, id string) error
|
||||
// Get the manifests for a compose.
|
||||
// (GET /compose/{id}/manifests)
|
||||
GetComposeIdManifests(ctx echo.Context, id string) error
|
||||
// status
|
||||
// (GET /status)
|
||||
GetStatus(ctx echo.Context) error
|
||||
|
|
@ -138,6 +141,22 @@ func (w *ServerInterfaceWrapper) GetComposeIdLogs(ctx echo.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// GetComposeIdManifests converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetComposeIdManifests(ctx echo.Context) error {
|
||||
var err error
|
||||
// ------------- Path parameter "id" -------------
|
||||
var id string
|
||||
|
||||
err = runtime.BindStyledParameter("simple", false, "id", ctx.Param("id"), &id)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
||||
}
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetComposeIdManifests(ctx, id)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetStatus converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetStatus(ctx echo.Context) error {
|
||||
var err error
|
||||
|
|
@ -172,6 +191,7 @@ func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
|||
router.POST("/compose", wrapper.PostCompose)
|
||||
router.GET("/compose/:id", wrapper.GetComposeId)
|
||||
router.GET("/compose/:id/logs", wrapper.GetComposeIdLogs)
|
||||
router.GET("/compose/:id/manifests", wrapper.GetComposeIdManifests)
|
||||
router.GET("/status", wrapper.GetStatus)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,36 @@ paths:
|
|||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
'/compose/{id}/manifests':
|
||||
get:
|
||||
summary: Get the manifests for a compose.
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
example: 123e4567-e89b-12d3-a456-426655440000
|
||||
required: true
|
||||
description: ID of compose status to get
|
||||
description: 'Get the manifests of a running or finished compose. Returns one manifest for each image in the request. Each manifest conforms to the format defined at https://www.osbuild.org/man/osbuild-manifest.5'
|
||||
responses:
|
||||
'200':
|
||||
description: The manifest for the given compose.
|
||||
content:
|
||||
application/json:
|
||||
'400':
|
||||
description: Invalid compose id
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
'404':
|
||||
description: Unknown compose id
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
/compose:
|
||||
post:
|
||||
summary: Create compose
|
||||
|
|
|
|||
|
|
@ -384,6 +384,37 @@ func (h *apiHandlers) GetComposeIdLogs(ctx echo.Context, idstr string) error {
|
|||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// GetComposeIdManifests returns the Manifests for a given Compose (one for each image).
|
||||
func (h *apiHandlers) GetComposeIdManifests(ctx echo.Context, idstr string) error {
|
||||
id, err := uuid.Parse(idstr)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
||||
}
|
||||
|
||||
var finalizeResult worker.KojiFinalizeJobResult
|
||||
_, deps, err := h.server.workers.JobStatus(id, &finalizeResult)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Job %s not found: %s", idstr, err))
|
||||
}
|
||||
|
||||
if len(deps) <= 1 {
|
||||
// ID matched a job ID that's not a Finalize job. Treat it as "not found".
|
||||
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Job %s not found: job does not exist", idstr))
|
||||
}
|
||||
|
||||
manifests := make([]distro.Manifest, len(deps)-1)
|
||||
for i, id := range deps[1:] {
|
||||
var buildJob worker.OSBuildKojiJob
|
||||
if _, err := h.server.workers.JobArgs(id, &buildJob); err != nil {
|
||||
// This is a programming error.
|
||||
panic(err)
|
||||
}
|
||||
manifests[i] = buildJob.Manifest
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusOK, manifests)
|
||||
}
|
||||
|
||||
// A simple echo.Binder(), which only accepts application/json, but is more
|
||||
// strict than echo's DefaultBinder. It does not handle binding query
|
||||
// parameters either.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue