-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathhash.go
More file actions
45 lines (35 loc) · 1.15 KB
/
hash.go
File metadata and controls
45 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"regexp"
"github.com/mitchellh/hashstructure/v2"
executionv1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func HashScanType(scanType executionv1.ScanType) uint64 {
hashTarget := executionv1.ScanType{}
hashTarget.Spec = scanType.Spec
metadata := metav1.ObjectMeta{}
metadata.Name = scanType.ObjectMeta.Name
metadata.Namespace = scanType.ObjectMeta.Namespace
metadata.Labels = filterOutNonScbMapElements(scanType.ObjectMeta.Labels)
metadata.Annotations = filterOutNonScbMapElements(scanType.ObjectMeta.Annotations)
hashTarget.ObjectMeta = metadata
hash, err := hashstructure.Hash(hashTarget, hashstructure.FormatV2, nil)
if err != nil {
panic(err)
}
return hash
}
func filterOutNonScbMapElements(m map[string]string) map[string]string {
filteredMap := map[string]string{}
re := regexp.MustCompile(`.*securecodebox\.io/.*`)
for key, value := range m {
if matches := re.MatchString(key); matches {
filteredMap[key] = value
}
}
return filteredMap
}