1
0
Fork 0
mirror of https://github.com/kyverno/policy-reporter.git synced 2024-12-14 11:57:32 +00:00
policy-reporter/pkg/report/model.go

72 lines
1.2 KiB
Go
Raw Normal View History

2021-02-19 23:58:01 +00:00
package report
import (
"github.com/kyverno/policy-reporter/pkg/crd/api/policyreport/v1alpha2"
)
2021-02-19 23:58:01 +00:00
// Event Enum
type Event int
func (e Event) String() string {
switch e {
case Added:
return "add"
case Updated:
return "update"
case Deleted:
return "delete"
}
return "unknown"
}
// Possible PolicyReport Event Enums
const (
Added Event = iota
Updated
Deleted
)
// LifecycleEvent of PolicyReports
type LifecycleEvent struct {
Type Event
PolicyReport v1alpha2.ReportInterface
}
// ResourceType Enum defined for PolicyReport
type ResourceType = string
// ReportType Enum
const (
PolicyReportType ResourceType = "PolicyReport"
ClusterPolicyReportType ResourceType = "ClusterPolicyReport"
)
func GetType(r v1alpha2.ReportInterface) ResourceType {
if r.GetNamespace() == "" {
return ClusterPolicyReportType
}
2021-02-20 12:54:02 +00:00
return PolicyReportType
2021-02-20 12:54:02 +00:00
}
func FindNewResults(nr, or v1alpha2.ReportInterface) []v1alpha2.PolicyReportResult {
if or == nil {
return nr.GetResults()
}
2021-02-20 12:54:02 +00:00
diff := make([]v1alpha2.PolicyReportResult, 0)
loop:
for _, r := range nr.GetResults() {
for _, o := range or.GetResults() {
if o.GetID() == r.GetID() {
continue loop
}
2021-02-20 12:54:02 +00:00
}
diff = append(diff, r)
}
return diff
}