Skip to content

Commit

Permalink
Conversion to PolicyReport is no longer required
Browse files Browse the repository at this point in the history
Signed-off-by: Takumi Yanagawa <yana@jp.ibm.com>
  • Loading branch information
yana1205 committed Dec 7, 2023
1 parent cdb6913 commit 6ca8ef3
Show file tree
Hide file tree
Showing 21 changed files with 1 addition and 975 deletions.
70 changes: 0 additions & 70 deletions cmd/ocm/oscal2posture/cmd/cmd.go

This file was deleted.

30 changes: 0 additions & 30 deletions cmd/ocm/oscal2posture/main.go

This file was deleted.

48 changes: 0 additions & 48 deletions cmd/ocm/oscal2posture/options/options.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/ocm/result2oscal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func Run(options *options.Options) error {
}

r := reporter.NewReporter(c2pcrParsed)
r.SetGenerationType(reporter.GenerationTypePolicyReport)
arRoot, err := r.Generate()
if err != nil {
panic(err)
Expand Down
65 changes: 0 additions & 65 deletions pkg/ocm/reporter/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ limitations under the License.
package reporter

import (
"fmt"
"strings"

"github.com/IBM/compliance-to-policy/pkg"
typeconfigpolicy "github.com/IBM/compliance-to-policy/pkg/types/configurationpolicy"
typepolicy "github.com/IBM/compliance-to-policy/pkg/types/policy"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
typepolr "sigs.k8s.io/wg-policy-prototypes/policy-report/pkg/api/wgpolicyk8s.io/v1beta1"
)

Expand Down Expand Up @@ -53,65 +47,6 @@ const (
PolicyResultSkip PolicyResult = "skip"
)

func ConvertToPolicyReport(policy typepolicy.Policy) typepolr.PolicyReport {
results := []*typepolr.PolicyReportResult{}
for _, pt := range policy.Spec.PolicyTemplates {
var configPolicy typeconfigpolicy.ConfigurationPolicy
if err := pkg.LoadByteToK8sTypedObject(pt.ObjectDefinition.Raw, &configPolicy); err != nil {
logger.Error(err.Error())
continue
}
subjects := []*corev1.ObjectReference{}
descriptions := []string{}
for _, ot := range configPolicy.Spec.ObjectTemplates {
var unstObj unstructured.Unstructured
if err := pkg.LoadByteToK8sTypedObject(ot.ObjectDefinition.Raw, &unstObj); err != nil {
logger.Error(err.Error())
continue
}
subject := corev1.ObjectReference{
Kind: unstObj.GetKind(),
APIVersion: unstObj.GetAPIVersion(),
Name: unstObj.GetName(),
Namespace: unstObj.GetNamespace(),
}
subjects = append(subjects, &subject)
descriptions = append(descriptions, fmt.Sprintf("%s Kind:%s Name:%s", ot.ComplianceType, unstObj.GetKind(), unstObj.GetName()))
}
details := findConfigPolicyStatus(policy, configPolicy)
result := typepolr.PolicyReportResult{
Policy: configPolicy.GetName(),
Description: strings.Join(descriptions, ","),
Subjects: subjects,
Result: mapToPolicyResult(details.ComplianceState),
Severity: mapToSeverity(configPolicy.Spec.Severity),
Properties: mapToProps(details),
Timestamp: mapToTimestamp(details),
}
results = append(results, &result)
}
policyReport := typepolr.PolicyReport{
TypeMeta: metav1.TypeMeta{
Kind: "PolicyReport",
APIVersion: "wgpolicyk8s.io/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: policy.Namespace,
Name: policy.Name,
CreationTimestamp: metav1.Now(),
},
Scope: &corev1.ObjectReference{
Kind: "Policy",
APIVersion: "policy.open-cluster-management.io/v1",
Namespace: policy.Namespace,
Name: policy.Name,
},
Results: results,
}
policyReport.Summary = summary(policyReport)
return policyReport
}

func mapToPolicyResult(complianceState typepolicy.ComplianceState) typepolr.PolicyResult {
var result PolicyResult
switch complianceState {
Expand Down
68 changes: 0 additions & 68 deletions pkg/ocm/reporter/helper_test.go

This file was deleted.

59 changes: 0 additions & 59 deletions pkg/ocm/reporter/markdown.go

This file was deleted.

Loading

0 comments on commit 6ca8ef3

Please sign in to comment.