Skip to content

Commit

Permalink
cloudapi/v2: populate openscap related rhsm facts
Browse files Browse the repository at this point in the history
Also adds the policy id to the blueprint, this doesn't have any effect
on the openscap step, it just puts in place the rhsm fact so instances
registered to insights will appear under that policy.
  • Loading branch information
croissanne committed Sep 5, 2024
1 parent 56d045f commit 1ba071a
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 180 deletions.
1 change: 1 addition & 0 deletions internal/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type OpenSCAPCustomization struct {
ProfileID string `json:"profile_id,omitempty" toml:"profile_id,omitempty"`
Tailoring *OpenSCAPTailoringCustomizations `json:"tailoring,omitempty" toml:"tailoring,omitempty"`
JSONTailoring *OpenSCAPJSONTailoringCustomizations `json:"json_tailoring,omitempty" toml:"json_tailoring,omitempty"`
PolicyID string `json:"policy_id,omitempty" toml:"policy_id,omitempty"`
}

type OpenSCAPTailoringCustomizations struct {
Expand Down
25 changes: 25 additions & 0 deletions internal/cloudapi/v2/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"math/big"
"reflect"

"github.com/google/uuid"

"github.com/osbuild/images/pkg/customizations/subscription"
"github.com/osbuild/images/pkg/disk"
"github.com/osbuild/images/pkg/distrofactory"
Expand Down Expand Up @@ -231,6 +233,11 @@ func (request *ComposeRequest) GetCustomizationsFromBlueprintRequest() (*bluepri
oscap := &blueprint.OpenSCAPCustomization{
ProfileID: rbpc.Openscap.ProfileId,
}

if rbpc.Openscap.PolicyId != nil {
oscap.PolicyID = *rbpc.Openscap.PolicyId
}

if rbpc.Openscap.Datastream != nil {
oscap.DataStream = *rbpc.Openscap.Datastream
}
Expand Down Expand Up @@ -739,6 +746,11 @@ func (request *ComposeRequest) GetBlueprintFromCustomizations() (blueprint.Bluep
openSCAPCustomization := &blueprint.OpenSCAPCustomization{
ProfileID: request.Customizations.Openscap.ProfileId,
}

if request.Customizations.Openscap.PolicyId != nil {
openSCAPCustomization.PolicyID = *request.Customizations.Openscap.PolicyId
}

if request.Customizations.Openscap.Tailoring != nil && request.Customizations.Openscap.JsonTailoring != nil {
return bp, fmt.Errorf("OpenSCAP customization error: choose one option between OpenSCAP tailoring and OpenSCAP json tailoring")
}
Expand Down Expand Up @@ -1163,6 +1175,19 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
imageOptions.Facts = &facts.ImageOptions{
APIType: facts.CLOUDV2_APITYPE,
}
oscap := bp.Customizations.GetOpenSCAP()
if oscap != nil {
if oscap.ProfileID != "" {
imageOptions.Facts.OpenSCAPProfileID = oscap.ProfileID
}
if oscap.PolicyID != "" {
policyID, err := uuid.Parse(oscap.PolicyID)
if err != nil {
return nil, fmt.Errorf("Unable to parse %s as a uuid: %w", oscap.PolicyID, err)
}
imageOptions.Facts.CompliancePolicyID = policyID
}
}
}

// Set Subscription from the compose request
Expand Down
Loading

0 comments on commit 1ba071a

Please sign in to comment.