Add the rhsm.facts stage.
We initially provide a Facts file that stores the `ApiType`. This is the API that was used to request the compose.
This commit is contained in:
parent
dba76a1204
commit
c5f335bceb
9 changed files with 111 additions and 16 deletions
|
|
@ -269,6 +269,10 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
imageOptions := distro.ImageOptions{Size: imageType.Size(0)}
|
||||
imageOptions.Facts = &distro.FactsImageOptions{
|
||||
ApiType: "cloudapi-v2",
|
||||
}
|
||||
|
||||
if request.Customizations != nil && request.Customizations.Subscription != nil {
|
||||
imageOptions.Subscription = &distro.SubscriptionImageOptions{
|
||||
Organization: request.Customizations.Subscription.Organization,
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ type ImageOptions struct {
|
|||
OSTree ostree.RequestParams
|
||||
Size uint64
|
||||
Subscription *SubscriptionImageOptions
|
||||
Facts *FactsImageOptions
|
||||
}
|
||||
|
||||
// The SubscriptionImageOptions specify subscription-specific image options
|
||||
|
|
@ -142,6 +143,12 @@ type SubscriptionImageOptions struct {
|
|||
Insights bool
|
||||
}
|
||||
|
||||
// The FactsImageOptions specify things to be stored into the Insights facts
|
||||
// storage. This mostly relates to how the build of the image was performed.
|
||||
type FactsImageOptions struct {
|
||||
ApiType string
|
||||
}
|
||||
|
||||
type BasePartitionTableMap map[string]disk.PartitionTable
|
||||
|
||||
// A Manifest is an opaque JSON object, which is a valid input to osbuild
|
||||
|
|
|
|||
|
|
@ -690,6 +690,14 @@ func osPipeline(t *imageType,
|
|||
p.AddStage(osbuild.NewSELinuxStage(selinuxStageOptions(false)))
|
||||
}
|
||||
|
||||
if options.Facts != nil {
|
||||
p.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
|
||||
Facts: osbuild.RHSMFacts{
|
||||
ApiType: options.Facts.ApiType,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
if t.rpmOstree {
|
||||
p.AddStage(osbuild.NewOSTreePrepTreeStage(&osbuild.OSTreePrepTreeStageOptions{
|
||||
EtcGroupMembers: []string{
|
||||
|
|
|
|||
|
|
@ -688,6 +688,14 @@ func osPipeline(t *imageType,
|
|||
p.AddStage(osbuild.NewSELinuxStage(selinuxStageOptions(false)))
|
||||
}
|
||||
|
||||
if options.Facts != nil {
|
||||
p.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
|
||||
Facts: osbuild.RHSMFacts{
|
||||
ApiType: options.Facts.ApiType,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
if t.rpmOstree {
|
||||
p.AddStage(osbuild.NewOSTreePrepTreeStage(&osbuild.OSTreePrepTreeStageOptions{
|
||||
EtcGroupMembers: []string{
|
||||
|
|
|
|||
19
internal/osbuild/rhsm_facts_stage.go
Normal file
19
internal/osbuild/rhsm_facts_stage.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package osbuild
|
||||
|
||||
type RHSMFactsStageOptions struct {
|
||||
Facts RHSMFacts `json:"facts"`
|
||||
}
|
||||
|
||||
type RHSMFacts struct {
|
||||
ApiType string `json:"image-builder.osbuild-composer.api-type"`
|
||||
}
|
||||
|
||||
func (RHSMFactsStageOptions) isStageOptions() {}
|
||||
|
||||
// NewRHSMFactsStage creates a new RHSM stage
|
||||
func NewRHSMFactsStage(options *RHSMFactsStageOptions) *Stage {
|
||||
return &Stage{
|
||||
Type: "org.osbuild.rhsm.facts",
|
||||
Options: options,
|
||||
}
|
||||
}
|
||||
46
internal/osbuild/rhsm_facts_stage_test.go
Normal file
46
internal/osbuild/rhsm_facts_stage_test.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package osbuild
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewRHSMFactsStage(t *testing.T) {
|
||||
expectedStage := &Stage{
|
||||
Type: "org.osbuild.rhsm.facts",
|
||||
Options: &RHSMFactsStageOptions{},
|
||||
}
|
||||
actualStage := NewRHSMFactsStage(&RHSMFactsStageOptions{})
|
||||
assert.Equal(t, expectedStage, actualStage)
|
||||
}
|
||||
|
||||
func TestRHSMFactsStageJson(t *testing.T) {
|
||||
tests := []struct {
|
||||
Options RHSMFactsStageOptions
|
||||
JsonString string
|
||||
}{
|
||||
{
|
||||
Options: RHSMFactsStageOptions{
|
||||
Facts: RHSMFacts{
|
||||
ApiType: "test-api",
|
||||
},
|
||||
},
|
||||
JsonString: fmt.Sprintf(`{"facts":{"image-builder.osbuild-composer.api-type":"%s"}}`, "test-api"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
marshaledJson, err := json.Marshal(test.Options)
|
||||
require.NoError(t, err, "failed to marshal JSON")
|
||||
require.Equal(t, test.JsonString, string(marshaledJson))
|
||||
|
||||
var jsonOptions RHSMFactsStageOptions
|
||||
err = json.Unmarshal([]byte(test.JsonString), &jsonOptions)
|
||||
require.NoError(t, err, "failed to parse JSON")
|
||||
require.True(t, reflect.DeepEqual(test.Options, jsonOptions))
|
||||
}
|
||||
}
|
||||
|
|
@ -2351,6 +2351,9 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
URL: cr.OSTree.URL,
|
||||
},
|
||||
}
|
||||
options.Facts = &distro.FactsImageOptions{
|
||||
ApiType: "weldr",
|
||||
}
|
||||
|
||||
packageSets, err := api.depsolveBlueprintForImageType(*bp, options, imageType)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue