store/ImageBuild: make Manifest a required property

Any valid ImageBuild must contain a Manifest, so don't allow this to be
nil, simplifying the code a bit in the process.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-05-31 17:57:30 +02:00
parent d606c5195b
commit 4aced4e749
6 changed files with 50 additions and 70 deletions

View file

@ -1670,16 +1670,16 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
testMode := q.Get("test")
if testMode == "1" {
// Create a failed compose
err = api.store.PushTestCompose(composeID, manifest, imageType, bp, size, targets, false)
err = api.store.PushTestCompose(composeID, *manifest, imageType, bp, size, targets, false)
} else if testMode == "2" {
// Create a successful compose
err = api.store.PushTestCompose(composeID, manifest, imageType, bp, size, targets, true)
err = api.store.PushTestCompose(composeID, *manifest, imageType, bp, size, targets, true)
} else {
var jobId uuid.UUID
jobId, err = api.workers.Enqueue(manifest, targets)
if err == nil {
err = api.store.PushCompose(composeID, manifest, imageType, bp, size, targets, jobId)
err = api.store.PushCompose(composeID, *manifest, imageType, bp, size, targets, jobId)
}
}
@ -2068,16 +2068,7 @@ func (api *API) composeMetadataHandler(writer http.ResponseWriter, request *http
return
}
// Return the Manifest, if it exists
if compose.ImageBuild.Manifest == nil {
errors := responseError{
ID: "EmptyManifest",
Msg: fmt.Sprintf("Manifest unexpectedly empty."),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
metadata, err := json.Marshal(compose.ImageBuild.Manifest)
metadata, err := json.Marshal(&compose.ImageBuild.Manifest)
common.PanicOnError(err)
writer.Header().Set("Content-Disposition", "attachment; filename="+uuid.String()+"-metadata.tar")
@ -2138,16 +2129,7 @@ func (api *API) composeResultsHandler(writer http.ResponseWriter, request *http.
return
}
// Return the Manifest, if it exists
if compose.ImageBuild.Manifest == nil {
errors := responseError{
ID: "EmptyManifest",
Msg: fmt.Sprintf("Manifest unexpectedly empty."),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
metadata, err := json.Marshal(compose.ImageBuild.Manifest)
metadata, err := json.Marshal(&compose.ImageBuild.Manifest)
common.PanicOnError(err)
writer.Header().Set("Content-Disposition", "attachment; filename="+uuid.String()+".tar")

View file

@ -13,6 +13,7 @@ import (
"time"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/target"
"github.com/osbuild/osbuild-composer/internal/blueprint"
@ -533,12 +534,11 @@ func TestCompose(t *testing.T) {
require.NotNilf(t, composeStruct.ImageBuild.Manifest, "%s: the compose in the store did not contain a blueprint", c.Path)
// TODO: find some (reasonable) way to verify the contents of the pipeline
composeStruct.ImageBuild.Manifest = nil
composeStruct.ImageBuild.Manifest = osbuild.Manifest{}
if diff := cmp.Diff(composeStruct, *c.ExpectedCompose, test.IgnoreDates(), test.IgnoreUuids(), test.Ignore("Targets.Options.Location"), test.CompareImageTypes()); diff != "" {
t.Errorf("%s: compose in store isn't the same as expected, diff:\n%s", c.Path, diff)
}
}
}
@ -639,10 +639,10 @@ func TestComposeLogs(t *testing.T) {
}{
{"/api/v0/compose/logs/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-logs.tar", "application/x-tar", "logs/osbuild.log", "The compose result is empty.\n"},
{"/api/v1/compose/logs/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-logs.tar", "application/x-tar", "logs/osbuild.log", "The compose result is empty.\n"},
{"/api/v0/compose/metadata/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-metadata.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":null,\"pipeline\":{}}"},
{"/api/v1/compose/metadata/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-metadata.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":null,\"pipeline\":{}}"},
{"/api/v0/compose/results/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":null,\"pipeline\":{}}"},
{"/api/v1/compose/results/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":null,\"pipeline\":{}}"},
{"/api/v0/compose/metadata/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-metadata.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":{},\"pipeline\":{}}"},
{"/api/v1/compose/metadata/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002-metadata.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":{},\"pipeline\":{}}"},
{"/api/v0/compose/results/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":{},\"pipeline\":{}}"},
{"/api/v1/compose/results/30000000-0000-0000-0000-000000000002", "attachment; filename=30000000-0000-0000-0000-000000000002.tar", "application/x-tar", "30000000-0000-0000-0000-000000000002.json", "{\"sources\":{},\"pipeline\":{}}"},
}
for _, c := range successCases {