From e791f51e2e42a4728a949ab72799181fdf805d96 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Fri, 14 Feb 2020 09:32:38 +0100 Subject: [PATCH] rcm: use pushcomposerequest instead of pushcompose the new version is better suited for the need of this API --- internal/rcm/api.go | 37 +++++++++++++++++++++++++++++++++---- internal/rcm/api_test.go | 3 +-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/internal/rcm/api.go b/internal/rcm/api.go index d1cae8caa..15a7757e8 100644 --- a/internal/rcm/api.go +++ b/internal/rcm/api.go @@ -4,7 +4,9 @@ package rcm import ( "encoding/json" + "fmt" "github.com/osbuild/osbuild-composer/internal/common" + "github.com/osbuild/osbuild-composer/internal/rpmmd" "log" "net" "net/http" @@ -127,13 +129,40 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http return } + // Create repo configurations from the URLs in the request. Use made up repo id and name, because + // we don't want to bother clients of this API with details like this + repoConfigs := []rpmmd.RepoConfig{} + for n, repo := range composeRequest.Repositories { + repoConfigs = append(repoConfigs, rpmmd.RepoConfig{ + Id: fmt.Sprintf("repo-%d", n), + Name: fmt.Sprintf("repo-%d", n), + BaseURL: repo.URL, + IgnoreSSL: false, + }) + } + + // Image requests are derived from requested image types. All of them are uploaded to Koji, because + // this API is only for RCM. + requestedImages := []common.ImageRequest{} + for _, imgType := range composeRequest.ImageTypes { + requestedImages = append(requestedImages, common.ImageRequest{ + ImgType: imgType, + // TODO: use koji upload type as soon as it is available + UpTarget: []common.UploadTarget{}, + }) + } + // Push the requested compose to the store composeUUID := uuid.New() // nil is used as an upload target, because LocalTarget is already used in the PushCompose function - // TODO: replace this with generalized version of push compose - arch, _ := composeRequest.Architectures[0].ToString() - imgType, _ := composeRequest.ImageTypes[0].ToCompatString() - err = api.store.PushCompose(composeUUID, &blueprint.Blueprint{}, nil, nil, make(map[string]string), arch, imgType, 0, nil) + err = api.store.PushComposeRequest(common.ComposeRequest{ + Blueprint: blueprint.Blueprint{}, + ComposeID: composeUUID, + Distro: composeRequest.Distribution, + Arch: composeRequest.Architectures[0], + Repositories: repoConfigs, + RequestedImages: requestedImages, + }) if err != nil { if api.logger != nil { api.logger.Println("RCM API failed to push compose:", err) diff --git a/internal/rcm/api_test.go b/internal/rcm/api_test.go index 57ac5f5bd..5cc3ac46f 100644 --- a/internal/rcm/api_test.go +++ b/internal/rcm/api_test.go @@ -2,7 +2,6 @@ package rcm_test import ( "bytes" - "encoding/json" "net/http" "net/http/httptest" "regexp" @@ -43,7 +42,7 @@ func TestBasicRcmAPI(t *testing.T) { {"GET", "/v1/compose", ``, "", http.StatusMethodNotAllowed, ``}, {"POST", "/v1/compose", `{"status":"RUNNING"}`, "application/json", http.StatusBadRequest, ``}, {"POST", "/v1/compose", `{"status":"RUNNING"}`, "text/plain", http.StatusBadRequest, ``}, - {"POST", "/v1/compose", `{"distribution": "fedora-30", "image_types": ["qcow2"], "architectures":["x86_64"], "repositories": [{"url": "aaa"}]}`, "application/json", http.StatusOK, `{"compose_id":".*"}`}, + {"POST", "/v1/compose", `{"distribution": "fedora-30", "image_types": ["qcow2"], "architectures":["x86_64"], "repositories": []}`, "application/json", http.StatusBadRequest, ""}, {"POST", "/v1/compose/111-222-333", `{"status":"RUNNING"}`, "application/json", http.StatusMethodNotAllowed, ``}, {"GET", "/v1/compose/7802c476-9cd1-41b7-ba81-43c1906bce73", `{"status":"RUNNING"}`, "application/json", http.StatusBadRequest, `{"error_reason":"Compose UUID does not exist"}`}, }