diff --git a/internal/worker/api/openapi.yml b/internal/worker/api/openapi.yml index e1b132c1f..e51d38f67 100644 --- a/internal/worker/api/openapi.yml +++ b/internal/worker/api/openapi.yml @@ -49,19 +49,20 @@ paths: type: object additionalProperties: false properties: - manifest: {} - targets: - type: array - items: {} + id: + type: string + format: uuid location: type: string artifact_location: type: string - id: + type: type: string - format: uuid + enum: + - osbuild + args: {} required: - - manifest + - type - location - id 4XX: diff --git a/internal/worker/client.go b/internal/worker/client.go index 8b6db3aed..bf33e6c9e 100644 --- a/internal/worker/client.go +++ b/internal/worker/client.go @@ -5,6 +5,7 @@ import ( "context" "crypto/tls" "encoding/json" + "errors" "fmt" "io" "net" @@ -35,10 +36,10 @@ type Job interface { type job struct { requester *http.Client id uuid.UUID - manifest distro.Manifest - targets []*target.Target location string artifactLocation string + jobType string + args json.RawMessage } func NewClient(baseURL string, conf *tls.Config) (*Client, error) { @@ -115,8 +116,8 @@ func (c *Client) RequestJob() (Job, error) { return &job{ requester: c.requester, id: jr.Id, - manifest: jr.Manifest, - targets: jr.Targets, + jobType: jr.Type, + args: jr.Args, location: location.String(), artifactLocation: artifactLocation.String(), }, nil @@ -127,7 +128,17 @@ func (j *job) Id() uuid.UUID { } func (j *job) OSBuildArgs() (distro.Manifest, []*target.Target, error) { - return j.manifest, j.targets, nil + if j.jobType != "osbuild" { + return nil, nil, errors.New("not an osbuild job") + } + + var args OSBuildJob + err := json.Unmarshal(j.args, &args) + if err != nil { + return nil, nil, fmt.Errorf("error parsing osbuild job arguments: %v", err) + } + + return args.Manifest, args.Targets, nil } func (j *job) Update(status common.ImageBuildState, result *osbuild.Result) error { diff --git a/internal/worker/json.go b/internal/worker/json.go index 60f95fc5c..977adc6a4 100644 --- a/internal/worker/json.go +++ b/internal/worker/json.go @@ -1,6 +1,8 @@ package worker import ( + "encoding/json" + "github.com/google/uuid" "github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/distro" @@ -30,11 +32,11 @@ type statusResponse struct { } type requestJobResponse struct { - Id uuid.UUID `json:"id"` - Manifest distro.Manifest `json:"manifest"` - Targets []*target.Target `json:"targets,omitempty"` - Location string `json:"location"` - ArtifactLocation string `json:"artifact_location"` + Id uuid.UUID `json:"id"` + Location string `json:"location"` + ArtifactLocation string `json:"artifact_location"` + Type string `json:"type"` + Args json.RawMessage `json:"args,omitempty"` } type getJobResponse struct { diff --git a/internal/worker/server.go b/internal/worker/server.go index 98b5012d0..9b33ed7c4 100644 --- a/internal/worker/server.go +++ b/internal/worker/server.go @@ -263,12 +263,17 @@ func (h *apiHandlers) RequestJob(ctx echo.Context) error { return err } + serializedArgs, err := json.Marshal(jobArgs) + if err != nil { + return err + } + return ctx.JSON(http.StatusCreated, requestJobResponse{ Id: jobId, - Manifest: jobArgs.Manifest, - Targets: jobArgs.Targets, Location: fmt.Sprintf("/jobs/%v", token), ArtifactLocation: fmt.Sprintf("/jobs/%v/artifacts/", token), + Type: "osbuild", + Args: serializedArgs, }) } diff --git a/internal/worker/server_test.go b/internal/worker/server_test.go index ee3200613..bbe31833a 100644 --- a/internal/worker/server_test.go +++ b/internal/worker/server_test.go @@ -68,7 +68,7 @@ func TestCreate(t *testing.T) { require.NoError(t, err) test.TestRoute(t, server, false, "POST", "/jobs", `{}`, http.StatusCreated, - `{"manifest":{"sources":{},"pipeline":{}}}`, "id", "location", "artifact_location") + `{"type":"osbuild","args":{"manifest":{"pipeline":{},"sources":{}}}}`, "id", "location", "artifact_location") } func TestCancel(t *testing.T) {