From 7a23a81228293d8389a72da3783e243ca9a58dd5 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Mon, 5 Jun 2023 23:07:00 +0200 Subject: [PATCH] ostree: use image options for request data The ostree options for a compose request should be specified using the ImageOptions struct, not the source spec. The source spec should be specifying the source parameters for a single ostree commit internally. --- internal/ostree/ostree.go | 22 +++++++++++----------- internal/weldr/api.go | 20 +++++++------------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/internal/ostree/ostree.go b/internal/ostree/ostree.go index d68ad1d1a..61988eefa 100644 --- a/internal/ostree/ostree.go +++ b/internal/ostree/ostree.go @@ -19,13 +19,13 @@ import ( var ostreeRefRE = regexp.MustCompile(`^(?:[\w\d][-._\w\d]*\/)*[\w\d][-._\w\d]*$`) -// SourceSpec serves as input for ResolveParams, and contains all necessary variables to resolve -// a ref, which can then be turned into a CommitSpec. +// SourceSpec serves as input for ResolveParams, and contains all necessary +// variables to resolve a ref, which can then be turned into a CommitSpec. type SourceSpec struct { - URL string `json:"url"` - Ref string `json:"ref"` - Parent string `json:"parent"` - RHSM bool `json:"rhsm"` + URL string + Ref string + Parent string + RHSM bool } // CommitSpec specifies an ostree commit using any combination of Ref (branch), URL (source), and Checksum (commit ID). @@ -54,22 +54,22 @@ type ImageOptions struct { // built. // For ostree installers and raw images: The ref of the commit being // embedded in the installer or deployed in the image. - ImageRef string + ImageRef string `json:"ref"` // For ostree commit and container types: The ParentRef specifies the parent // ostree commit that the new commit will be based on. // For ostree installers and raw images: The ParentRef does not apply. - ParentRef string + ParentRef string `json:"parent"` // The URL from which to fetch the commit specified by the checksum. - URL string + URL string `json:"url"` // If specified, the URL will be used only for metadata. - ContentURL string + ContentURL string `json:"contenturl"` // Indicate if the 'org.osbuild.rhsm.consumer' secret should be added when pulling from the // remote. - RHSM bool + RHSM bool `json:"rhsm"` } // Remote defines the options that can be set for an OSTree Remote configuration. diff --git a/internal/weldr/api.go b/internal/weldr/api.go index d93fdb6c7..098832ef5 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -2372,12 +2372,12 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request // https://weldr.io/lorax/pylorax.api.html#pylorax.api.v0.v0_compose_start type ComposeRequest struct { - BlueprintName string `json:"blueprint_name"` - ComposeType string `json:"compose_type"` - Size uint64 `json:"size"` - OSTree ostree.SourceSpec `json:"ostree"` - Branch string `json:"branch"` - Upload *uploadRequest `json:"upload"` + BlueprintName string `json:"blueprint_name"` + ComposeType string `json:"compose_type"` + Size uint64 `json:"size"` + OSTree ostree.ImageOptions `json:"ostree"` + Branch string `json:"branch"` + Upload *uploadRequest `json:"upload"` } type ComposeReply struct { BuildID uuid.UUID `json:"build_id"` @@ -2469,12 +2469,6 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request statusResponseError(writer, http.StatusBadRequest, errors) return } - ostreeOptions := &ostree.ImageOptions{ - ImageRef: cr.OSTree.Ref, - ParentRef: cr.OSTree.Parent, - URL: cr.OSTree.URL, - RHSM: cr.OSTree.RHSM, - } var size uint64 @@ -2495,7 +2489,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request options := distro.ImageOptions{ Size: size, - OSTree: ostreeOptions, + OSTree: &cr.OSTree, } options.Facts = &facts.ImageOptions{ APIType: facts.WELDR_APITYPE,