-
Notifications
You must be signed in to change notification settings - Fork 80
/
operation.go
39 lines (35 loc) · 941 Bytes
/
operation.go
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
package ovalutil
import (
"regexp"
"strings"
"github.com/quay/goval-parser/oval"
)
// Operation check if values match based on given operation
func Operation(value, requiredValue string, operation oval.Operation) bool {
switch operation {
case oval.OpEquals:
return value == requiredValue
case oval.OpNotEquals:
return value != requiredValue
case oval.OpCaseInsensitiveEquals:
return strings.EqualFold(value, requiredValue)
case oval.OpCaseInsensitiveNotEquals:
return !strings.EqualFold(value, requiredValue)
case oval.OpGreaterThan:
return value > requiredValue
case oval.OpLessThan:
return value < requiredValue
case oval.OpGreaterThanOrEqual:
return value >= requiredValue
case oval.OpLessThanOrEqual:
return value <= requiredValue
case oval.OpPatternMatch:
exp, err := regexp.Compile(requiredValue)
if err != nil {
return false
}
return exp.Match([]byte(value))
default:
return false
}
}