2021-02-19 23:58:01 +00:00
|
|
|
package report
|
|
|
|
|
2021-02-22 00:13:35 +00:00
|
|
|
import (
|
2023-02-07 10:21:48 +00:00
|
|
|
"github.com/kyverno/policy-reporter/pkg/crd/api/policyreport/v1alpha2"
|
2021-02-22 00:13:35 +00:00
|
|
|
)
|
2021-02-19 23:58:01 +00:00
|
|
|
|
2021-12-13 15:02:40 +00:00
|
|
|
// Event Enum
|
2022-06-03 15:03:58 +00:00
|
|
|
type Event int
|
|
|
|
|
|
|
|
func (e Event) String() string {
|
|
|
|
switch e {
|
|
|
|
case Added:
|
|
|
|
return "add"
|
|
|
|
case Updated:
|
|
|
|
return "update"
|
|
|
|
case Deleted:
|
|
|
|
return "delete"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown"
|
|
|
|
}
|
2021-12-13 15:02:40 +00:00
|
|
|
|
|
|
|
// Possible PolicyReport Event Enums
|
|
|
|
const (
|
|
|
|
Added Event = iota
|
|
|
|
Updated
|
|
|
|
Deleted
|
|
|
|
)
|
|
|
|
|
|
|
|
// LifecycleEvent of PolicyReports
|
|
|
|
type LifecycleEvent struct {
|
2023-02-08 14:53:59 +00:00
|
|
|
Type Event
|
|
|
|
PolicyReport v1alpha2.ReportInterface
|
2021-12-13 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceType Enum defined for PolicyReport
|
|
|
|
type ResourceType = string
|
2021-05-18 11:50:02 +00:00
|
|
|
|
2021-05-26 19:40:04 +00:00
|
|
|
// ReportType Enum
|
2021-05-18 11:50:02 +00:00
|
|
|
const (
|
2021-12-13 15:02:40 +00:00
|
|
|
PolicyReportType ResourceType = "PolicyReport"
|
|
|
|
ClusterPolicyReportType ResourceType = "ClusterPolicyReport"
|
2021-05-18 11:50:02 +00:00
|
|
|
)
|
|
|
|
|
2023-02-07 10:21:48 +00:00
|
|
|
func GetType(r v1alpha2.ReportInterface) ResourceType {
|
|
|
|
if r.GetNamespace() == "" {
|
2021-05-18 11:50:02 +00:00
|
|
|
return ClusterPolicyReportType
|
|
|
|
}
|
2021-02-20 12:54:02 +00:00
|
|
|
|
2021-05-18 11:50:02 +00:00
|
|
|
return PolicyReportType
|
2021-02-20 12:54:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 10:21:48 +00:00
|
|
|
func FindNewResults(nr, or v1alpha2.ReportInterface) []v1alpha2.PolicyReportResult {
|
|
|
|
if or == nil {
|
|
|
|
return nr.GetResults()
|
|
|
|
}
|
2021-02-20 12:54:02 +00:00
|
|
|
|
2023-02-07 10:21:48 +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
|
|
|
|
}
|