Skip to content

Commit

Permalink
CMP-2130: Implement support for profile versioning
Browse files Browse the repository at this point in the history
This commit adds support for an optional version attribute for Profile
custom resources. This attribute is parsed out of the datastream and set
on the Profile by the compliance operator. It's not intended for end
users to supply their own version.

Future patches may expand on this concept to support multiple versions
of a single profile.
  • Loading branch information
rhmdnd committed Oct 13, 2023
1 parent bfdf204 commit e92f501
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
more ergonomic to pause scans during maintenance periods. See the
[enhancement](https://github.com/ComplianceAsCode/compliance-operator/pull/375)
for more details.
- Implemented support for an optional `version` attribute on `Profile` custom
resources.

### Fixes

Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/compliance.openshift.io_profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ spec:
nullable: true
type: array
x-kubernetes-list-type: atomic
versions:
items:
type: string
type: array
required:
- description
- id
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/compliance/v1alpha1/profile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type ProfilePayload struct {
// +optional
// +listType=atomic
Values []ProfileValue `json:"values,omitempty"`
// +optional
Versions []string `json:"versions"`
}

// +kubebuilder:object:root=true
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/compliance/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/profileparser/profileparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ func parseProfileFromNode(profileRoot *xmlquery.Node, pb *cmpv1alpha1.ProfileBun
if description == nil {
return LogAndReturnError("no description in profile")
}
v := profileObj.SelectElement("xccdf-1.2:version")
var versions []string
if v != nil {
versions = append(versions, v.InnerText())
}
log.Info("Found profile", "id", id)

// In case the profile sets its own CPE string
Expand Down Expand Up @@ -362,6 +367,7 @@ func parseProfileFromNode(profileRoot *xmlquery.Node, pb *cmpv1alpha1.ProfileBun
Description: utils.XmlNodeAsMarkdown(description),
Rules: selectedrules,
Values: selectedvalues,
Versions: versions,
},
}

Expand Down

0 comments on commit e92f501

Please sign in to comment.