store: give ComposeRequest a real distro
`ComposeRequest` included a `common.Distribution`, which had to be resolved in PushComposeRequest. Use a real `distro.Distro` object here, and push resolving it to the rcm package. Change the `Distribution` on the (lower-case) `composeRequest` to a string. This struct represents the incoming request. Since we're now resolving the real distro object from the registry in the same function, it seems redundant to validate the incoming distro twice.
This commit is contained in:
parent
f68679c09f
commit
c2c8fae093
4 changed files with 20 additions and 24 deletions
|
|
@ -116,7 +116,7 @@ func main() {
|
|||
log.Fatal("The RCM API socket unit is misconfigured. It should contain only one socket.")
|
||||
}
|
||||
rcmListener := rcmApiListeners[0]
|
||||
rcmAPI := rcm.New(logger, store, rpm)
|
||||
rcmAPI := rcm.New(logger, store, rpm, distros)
|
||||
go func() {
|
||||
err := rcmAPI.Serve(rcmListener)
|
||||
// If the RCM API fails, take down the whole process, not just a single gorutine
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
)
|
||||
|
||||
|
|
@ -27,15 +28,17 @@ type API struct {
|
|||
// rpmMetadata is an interface to dnf-json and we include it here so that we can
|
||||
// mock it in the unit tests
|
||||
rpmMetadata rpmmd.RPMMD
|
||||
distros *distro.Registry
|
||||
}
|
||||
|
||||
// New creates new RCM API
|
||||
func New(logger *log.Logger, store *store.Store, rpmMetadata rpmmd.RPMMD) *API {
|
||||
func New(logger *log.Logger, store *store.Store, rpmMetadata rpmmd.RPMMD, distros *distro.Registry) *API {
|
||||
api := &API{
|
||||
logger: logger,
|
||||
store: store,
|
||||
router: httprouter.New(),
|
||||
rpmMetadata: rpmMetadata,
|
||||
distros: distros,
|
||||
}
|
||||
|
||||
api.router.RedirectTrailingSlash = false
|
||||
|
|
@ -93,7 +96,7 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
|
||||
// JSON structure expected from the client
|
||||
var composeRequest struct {
|
||||
Distribution common.Distribution `json:"distribution"`
|
||||
Distribution string `json:"distribution"`
|
||||
ImageTypes []common.ImageType `json:"image_types"`
|
||||
Architectures []common.Architecture `json:"architectures"`
|
||||
Repositories []Repository `json:"repositories"`
|
||||
|
|
@ -156,17 +159,17 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
})
|
||||
}
|
||||
|
||||
modulePlatformID, err := composeRequest.Distribution.ModulePlatformID()
|
||||
if err != nil {
|
||||
distro := api.distros.GetDistro(composeRequest.Distribution)
|
||||
if distro == nil {
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
_, err := writer.Write([]byte(err.Error()))
|
||||
_, err := writer.Write([]byte("unknown distro"))
|
||||
if err != nil {
|
||||
panic("Failed to write response")
|
||||
}
|
||||
}
|
||||
|
||||
// map( repo-id => checksum )
|
||||
_, checksums, err := api.rpmMetadata.FetchMetadata(repoConfigs, modulePlatformID)
|
||||
_, checksums, err := api.rpmMetadata.FetchMetadata(repoConfigs, distro.ModulePlatformID())
|
||||
if err != nil {
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
_, err := writer.Write([]byte(err.Error()))
|
||||
|
|
@ -181,7 +184,7 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
err = api.store.PushComposeRequest(store.ComposeRequest{
|
||||
Blueprint: blueprint.Blueprint{},
|
||||
ComposeID: composeUUID,
|
||||
Distro: composeRequest.Distribution,
|
||||
Distro: distro,
|
||||
Arch: composeRequest.Architectures[0],
|
||||
Repositories: repoConfigs,
|
||||
Checksums: checksums,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func TestBasicRcmAPI(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
distroStruct := fedoratest.New()
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
|
||||
for _, c := range cases {
|
||||
resp := internalRequest(api, c.Method, c.Path, c.Body, c.ContentType)
|
||||
|
|
@ -81,7 +81,7 @@ func TestSubmitCompose(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
|
||||
var submit_reply struct {
|
||||
UUID uuid.UUID `json:"compose_id"`
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -74,7 +73,7 @@ type SourceConfig struct {
|
|||
type ComposeRequest struct {
|
||||
Blueprint blueprint.Blueprint
|
||||
ComposeID uuid.UUID
|
||||
Distro common.Distribution
|
||||
Distro distro.Distro
|
||||
Arch common.Architecture
|
||||
Repositories []rpmmd.RepoConfig
|
||||
Checksums map[string]string
|
||||
|
|
@ -662,15 +661,6 @@ func (s *Store) PushComposeRequest(request ComposeRequest) error {
|
|||
if !exists {
|
||||
panic("fatal error, arch should exist but it does not")
|
||||
}
|
||||
distroString, exists := request.Distro.ToString()
|
||||
if !exists {
|
||||
panic("fatal error, distro should exist but it does not")
|
||||
}
|
||||
|
||||
distroStruct := s.distroRegistry.GetDistro(distroString)
|
||||
if distroStruct == nil || (reflect.ValueOf(distroStruct).Kind() == reflect.Ptr && reflect.ValueOf(distroStruct).IsNil()) {
|
||||
panic("fatal error, distro should exist but it is not in the registry")
|
||||
}
|
||||
|
||||
// This will be a list of imageBuilds that will be submitted to the state channel
|
||||
imageBuilds := []compose.ImageBuild{}
|
||||
|
|
@ -689,7 +679,7 @@ func (s *Store) PushComposeRequest(request ComposeRequest) error {
|
|||
if !exists {
|
||||
panic("fatal error, image type should exist but it does not")
|
||||
}
|
||||
manifestStruct, err := distroStruct.Manifest(request.Blueprint.Customizations, request.Repositories, nil, nil, arch, imgTypeCompatStr, 0)
|
||||
manifestStruct, err := request.Distro.Manifest(request.Blueprint.Customizations, request.Repositories, nil, nil, arch, imgTypeCompatStr, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -705,14 +695,17 @@ func (s *Store) PushComposeRequest(request ComposeRequest) error {
|
|||
newJobs = append(newJobs, Job{
|
||||
ComposeID: request.ComposeID,
|
||||
ImageBuildID: imageBuildID,
|
||||
Distro: distroString,
|
||||
Distro: request.Distro.Name(),
|
||||
Manifest: manifestStruct,
|
||||
Targets: []*target.Target{},
|
||||
ImageType: imgTypeCompatStr,
|
||||
})
|
||||
|
||||
// this ought to exist, because we're creating it from an existing distro struct
|
||||
distroTag, _ := common.DistributionFromString(request.Distro.Name())
|
||||
|
||||
imageBuilds = append(imageBuilds, compose.ImageBuild{
|
||||
Distro: request.Distro,
|
||||
Distro: distroTag,
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imageRequest.ImgType,
|
||||
Manifest: manifestStruct,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue