rhsm: move FactsImageOptions to the rhsm/facts package

Move the FactsImageOptions from distro to the new rhsm/facts package.
At the same time define the values we use as an enum, including the
"test-manifest" value.
Though the values don't really matter, the test value is defined first
so it takes the 0 value, which feels nicer conceptually.

The field in the distro.ImageOptions is changed to be a pointer to allow
for nil values.
This commit is contained in:
Achilleas Koutsou 2023-05-05 14:46:39 +02:00 committed by Simon de Vlieger
parent f1557fc4e4
commit ffa1e1df17
10 changed files with 50 additions and 21 deletions

View file

@ -22,6 +22,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -130,8 +131,8 @@ func makeManifestJob(name string, imgType distro.ImageType, cr composeRequest, d
}
// add RHSM fact to detect changes
options.Facts = &distro.FactsImageOptions{
ApiType: "test-manifest",
options.Facts = &facts.ImageOptions{
APIType: facts.TEST_APITYPE,
}
job := func(msgq chan string) (err error) {

View file

@ -21,6 +21,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/subscription"
"github.com/osbuild/osbuild-composer/internal/target"
@ -437,8 +438,8 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
imageOptions := distro.ImageOptions{Size: imageType.Size(0)}
if request.Koji == nil {
imageOptions.Facts = &distro.FactsImageOptions{
ApiType: "cloudapi-v2",
imageOptions.Facts = &facts.ImageOptions{
APIType: facts.CLOUDV2_APITYPE,
}
}

View file

@ -7,6 +7,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/container"
"github.com/osbuild/osbuild-composer/internal/disk"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/subscription"
)
@ -139,7 +140,7 @@ type ImageOptions struct {
Size uint64
OSTree OSTreeImageOptions
Subscription *subscription.ImageOptions
Facts *FactsImageOptions
Facts *facts.ImageOptions
}
// The OSTreeImageOptions specify an ostree ref, checksum, URL, ContentURL, and RHSM. The meaning of
@ -168,12 +169,6 @@ type OSTreeImageOptions struct {
RHSM 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
// Fallbacks: When a new method is added to an interface to provide to provide

View file

@ -20,6 +20,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/dnfjson"
"github.com/osbuild/osbuild-composer/internal/manifest"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
@ -118,8 +119,8 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis
options := distro.ImageOptions{
Size: imageType.Size(0),
OSTree: ostreeOptions,
Facts: &distro.FactsImageOptions{
ApiType: "test-manifest",
Facts: &facts.ImageOptions{
APIType: facts.TEST_APITYPE,
},
}

View file

@ -139,7 +139,7 @@ func osCustomizations(
}
if t.arch.distro.isRHEL() && options.Facts != nil {
osc.FactAPIType = options.Facts.ApiType
osc.FactAPIType = &options.Facts.APIType
}
var err error

View file

@ -145,7 +145,7 @@ func osCustomizations(
}
if t.arch.distro.isRHEL() && options.Facts != nil {
osc.FactAPIType = options.Facts.ApiType
osc.FactAPIType = &options.Facts.APIType
}
var err error

View file

@ -142,7 +142,7 @@ func osCustomizations(
}
if t.arch.distro.isRHEL() && options.Facts != nil {
osc.FactAPIType = options.Facts.ApiType
osc.FactAPIType = &options.Facts.APIType
}
var err error

View file

@ -13,6 +13,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/platform"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/shell"
"github.com/osbuild/osbuild-composer/internal/subscription"
@ -118,7 +119,7 @@ type OSCustomizations struct {
WAAgentConfig *osbuild.WAAgentConfStageOptions
UdevRules *osbuild.UdevRulesStageOptions
LeapSecTZ *string
FactAPIType string
FactAPIType *facts.APIType
Subscription *subscription.ImageOptions
RHSMConfig map[subscription.RHSMStatus]*osbuild.RHSMStageOptions
@ -605,10 +606,10 @@ func (p *OS) serialize() osbuild.Pipeline {
pipeline.AddStage(osbuild.NewOscapRemediationStage(p.OpenSCAPConfig))
}
if p.FactAPIType != "" {
if p.FactAPIType != nil {
pipeline.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
Facts: osbuild.RHSMFacts{
ApiType: p.FactAPIType,
ApiType: p.FactAPIType.String(),
},
}))
}

View file

@ -0,0 +1,29 @@
package facts
import "fmt"
type APIType uint64
func (at APIType) String() string {
switch at {
case TEST_APITYPE:
return "test-manifest"
case CLOUDV2_APITYPE:
return "cloudapi-v2"
case WELDR_APITYPE:
return "weldr"
}
panic(fmt.Sprintf("invalid APIType value %d", at))
}
const (
TEST_APITYPE APIType = iota
CLOUDV2_APITYPE
WELDR_APITYPE
)
// The ImageOptions specify things to be stored into the Insights facts
// storage. This mostly relates to how the build of the image was performed.
type ImageOptions struct {
APIType APIType
}

View file

@ -39,6 +39,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/reporegistry"
"github.com/osbuild/osbuild-composer/internal/rhsm/facts"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/store"
"github.com/osbuild/osbuild-composer/internal/target"
@ -2497,8 +2498,8 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
Size: size,
OSTree: ostreeOptions,
}
options.Facts = &distro.FactsImageOptions{
ApiType: "weldr",
options.Facts = &facts.ImageOptions{
APIType: facts.WELDR_APITYPE,
}
packageSets, err := api.depsolveBlueprintForImageType(*bp, options, imageType)