diff --git a/internal/job/job.go b/internal/job/job.go index 262138baf..21b485e08 100644 --- a/internal/job/job.go +++ b/internal/job/job.go @@ -10,7 +10,7 @@ import ( type Job struct { ComposeID uuid.UUID Pipeline pipeline.Pipeline - Targets []target.Target + Targets []*target.Target } type Status struct { diff --git a/internal/jobqueue/api.go b/internal/jobqueue/api.go index 9f11df023..24a0a7ff1 100644 --- a/internal/jobqueue/api.go +++ b/internal/jobqueue/api.go @@ -84,7 +84,7 @@ func (api *API) addJobHandler(writer http.ResponseWriter, request *http.Request, } type replyBody struct { Pipeline pipeline.Pipeline `json:"pipeline"` - Targets []target.Target `json:"targets"` + Targets []*target.Target `json:"targets"` } contentType := request.Header["Content-Type"] diff --git a/internal/jobqueue/api_test.go b/internal/jobqueue/api_test.go index f9e49f62b..4a33da279 100644 --- a/internal/jobqueue/api_test.go +++ b/internal/jobqueue/api_test.go @@ -66,7 +66,7 @@ func testRoute(t *testing.T, api *jobqueue.API, method, path, body string, expec } func TestBasic(t *testing.T) { - expected_job := `{"pipeline":{"assembler":{"name":"org.osbuild.tar","options":{"filename":"image.tar"}}},"targets":[{"name":"org.osbuild.local","options":{"location":"/var/lib/osbuild-composer/ffffffff-ffff-ffff-ffff-ffffffffffff"}}]}` + expected_job := `{"pipeline":{"assembler":{"name":"org.osbuild.tar","options":{"filename":"image.tar"}}},"targets":[{"name":"org.osbuild.local","options":{"location":"/var/lib/osbuild-composer/outputs/ffffffff-ffff-ffff-ffff-ffffffffffff"}}]}` var cases = []struct { Method string Path string @@ -104,12 +104,7 @@ func TestBasic(t *testing.T) { }, }, }, - Targets: []target.Target{{ - Name: "org.osbuild.local", - Options: target.LocalOptions{ - Location: "/var/lib/osbuild-composer/ffffffff-ffff-ffff-ffff-ffffffffffff", - }}, - }, + Targets: []*target.Target{target.New(id)}, } testRoute(t, api, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedJSON) diff --git a/internal/target/target.go b/internal/target/target.go index de28142f7..3e69f9dd3 100644 --- a/internal/target/target.go +++ b/internal/target/target.go @@ -1,10 +1,21 @@ package target +import "github.com/google/uuid" + type Target struct { - Name string `json:"name"` - Options LocalOptions `json:"options"` + Name string `json:"name"` + Options Options `json:"options"` } -type LocalOptions struct { +type Options struct { Location string `json:"location"` } + +func New(ComposeID uuid.UUID) *Target { + return &Target{ + Name: "org.osbuild.local", + Options: Options{ + Location: "/var/lib/osbuild-composer/outputs/" + ComposeID.String(), + }, + } +} diff --git a/internal/weldr/store.go b/internal/weldr/store.go index 9f399e9c9..32551f5bc 100644 --- a/internal/weldr/store.go +++ b/internal/weldr/store.go @@ -39,7 +39,7 @@ type blueprintPackage struct { type compose struct { Status string `json:"status"` Pipeline pipeline.Pipeline `json:"pipeline"` - Targets []target.Target `json:"targets"` + Targets []*target.Target `json:"targets"` } func newStore(initialState []byte, stateChannel chan<- []byte, pendingJobs chan<- job.Job, jobUpdates <-chan job.Status) *store { @@ -190,12 +190,7 @@ func (s *store) deleteBlueprintFromWorkspace(name string) { func (s *store) addCompose(composeID uuid.UUID, bp blueprint, composeType string) { pipeline := bp.translateToPipeline(composeType) - targets := []target.Target{{ - Name: "org.osbuild.local", - Options: target.LocalOptions{ - Location: "/var/lib/osbuild-composer/" + composeID.String(), - }, - }} + targets := []*target.Target{target.New(composeID)} s.change(func() { s.Composes[composeID] = compose{"pending", pipeline, targets} })