github.com/quay/claircore@v1.5.28/pkg/ovalutil/operation.go (about)

     1  package ovalutil
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  
     7  	"github.com/quay/goval-parser/oval"
     8  )
     9  
    10  // Operation check if values match based on given operation
    11  func Operation(value, requiredValue string, operation oval.Operation) bool {
    12  	switch operation {
    13  	case oval.OpEquals:
    14  		return value == requiredValue
    15  	case oval.OpNotEquals:
    16  		return value != requiredValue
    17  	case oval.OpCaseInsensitiveEquals:
    18  		return strings.EqualFold(value, requiredValue)
    19  	case oval.OpCaseInsensitiveNotEquals:
    20  		return !strings.EqualFold(value, requiredValue)
    21  	case oval.OpGreaterThan:
    22  		return value > requiredValue
    23  	case oval.OpLessThan:
    24  		return value < requiredValue
    25  	case oval.OpGreaterThanOrEqual:
    26  		return value >= requiredValue
    27  	case oval.OpLessThanOrEqual:
    28  		return value <= requiredValue
    29  	case oval.OpPatternMatch:
    30  		exp, err := regexp.Compile(requiredValue)
    31  		if err != nil {
    32  			return false
    33  		}
    34  		return exp.Match([]byte(value))
    35  
    36  	default:
    37  		return false
    38  	}
    39  }