mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
log label conversion issues
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
This commit is contained in:
parent
d9704c96f5
commit
318f2e9570
1 changed files with 88 additions and 74 deletions
|
@ -100,7 +100,11 @@ func (s *policyReportStore) Get(id string) (report.PolicyReport, bool) {
|
|||
}
|
||||
|
||||
r.CreationTimestamp = time.Unix(created, 0)
|
||||
r.Labels = convertJSONToMap(labels)
|
||||
r.Labels, err = convertJSONToMap(labels)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] failed to convert json to labels: %s\n", err)
|
||||
return r, false
|
||||
}
|
||||
|
||||
results, err := s.fetchResults(id)
|
||||
if err != nil {
|
||||
|
@ -860,7 +864,11 @@ func (s *policyReportStore) FetchNamespacedReportLabels(filter api.Filter) (map[
|
|||
if err != nil {
|
||||
return list, err
|
||||
}
|
||||
labels := convertJSONToMap(item)
|
||||
labels, err := convertJSONToMap(item)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] failed to convert json to labels: %s\n", err)
|
||||
}
|
||||
|
||||
for key, value := range labels {
|
||||
if _, ok := list[key]; ok && !contains(value, list[key]) {
|
||||
list[key] = append(list[key], value)
|
||||
|
@ -893,7 +901,11 @@ func (s *policyReportStore) FetchClusterReportLabels(filter api.Filter) (map[str
|
|||
if err != nil {
|
||||
return list, err
|
||||
}
|
||||
labels := convertJSONToMap(item)
|
||||
labels, err := convertJSONToMap(item)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] failed to convert json to labels: %s\n", err)
|
||||
}
|
||||
|
||||
for key, value := range labels {
|
||||
if _, ok := list[key]; ok && !contains(value, list[key]) {
|
||||
list[key] = append(list[key], value)
|
||||
|
@ -1110,13 +1122,14 @@ func generateFilterWhere(filter api.Filter, active []string) (string, []interfac
|
|||
argCounter += 2
|
||||
|
||||
where = append(where, fmt.Sprintf(
|
||||
`(resource_namespace LIKE $%d OR resource_name LIKE $%d OR policy LIKE $%d OR rule LIKE $%d OR severity = $%d OR status = $%d)`,
|
||||
`(resource_namespace LIKE $%d OR resource_name LIKE $%d OR policy LIKE $%d OR rule LIKE $%d OR severity = $%d OR status = $%d OR LOWER(resource_kind) = LOWER($%d))`,
|
||||
likeIndex,
|
||||
likeIndex,
|
||||
likeIndex,
|
||||
likeIndex,
|
||||
equalIndex,
|
||||
equalIndex,
|
||||
equalIndex,
|
||||
))
|
||||
args = append(args, filter.Search+"%", filter.Search)
|
||||
}
|
||||
|
@ -1163,17 +1176,18 @@ func contains(source string, sources []string) bool {
|
|||
func convertMapToJSON(m map[string]string) string {
|
||||
str, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] failed to convert map to json: %s\n", err)
|
||||
return "{}"
|
||||
}
|
||||
|
||||
return string(str)
|
||||
}
|
||||
|
||||
func convertJSONToMap(s string) map[string]string {
|
||||
func convertJSONToMap(s string) (map[string]string, error) {
|
||||
m := make(map[string]string)
|
||||
_ = json.Unmarshal([]byte(s), &m)
|
||||
err := json.Unmarshal([]byte(s), &m)
|
||||
|
||||
return m
|
||||
return m, err
|
||||
}
|
||||
|
||||
// NewPolicyReportStore construct a PolicyReportStore
|
||||
|
|
Loading…
Reference in a new issue