crowdsec/pkg/cwversion/constraint/constraint.go
mmetc cae76baa3a
refact acquisition: build profiles (optionally exclude datasources from final binary) (#3217)
example

$ make BUILD_PROFILE=minimal

or

$ make EXCLUDE=datasource_s3,datasource_kinesis
2024-09-12 17:26:39 +02:00

32 lines
626 B
Go

package constraint
import (
"fmt"
goversion "github.com/hashicorp/go-version"
)
const (
Parser = ">= 1.0, <= 3.0"
Scenario = ">= 1.0, <= 3.0"
API = "v1"
Acquis = ">= 1.0, < 2.0"
)
func Satisfies(strvers string, constraint string) (bool, error) {
vers, err := goversion.NewVersion(strvers)
if err != nil {
return false, fmt.Errorf("failed to parse '%s': %w", strvers, err)
}
constraints, err := goversion.NewConstraint(constraint)
if err != nil {
return false, fmt.Errorf("failed to parse constraint '%s'", constraint)
}
if !constraints.Check(vers) {
return false, nil
}
return true, nil
}