mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-29 07:49:14 +01:00
[management] optimize posture cache (#8366)
This commit is contained in:
@@ -2,6 +2,7 @@ package nmdata
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
)
|
||||
@@ -9,27 +10,26 @@ import (
|
||||
// NBVersionCheck is the slim twin of posture.NBVersionCheck.
|
||||
type NBVersionCheck struct {
|
||||
MinVersion string
|
||||
|
||||
constraintOnce sync.Once
|
||||
constraint version.Constraints
|
||||
constraintErr error
|
||||
}
|
||||
|
||||
func (n *NBVersionCheck) check(peer *Peer) (bool, error) {
|
||||
return meetsMinVersion(n.MinVersion, peer.Meta.WtVersion)
|
||||
}
|
||||
|
||||
func meetsMinVersion(minVer, peerVer string) (bool, error) {
|
||||
peerVer = sanitizeVersion(peerVer)
|
||||
minVer = sanitizeVersion(minVer)
|
||||
|
||||
peerNBVer, err := version.NewVersion(peerVer)
|
||||
peerNBVer, err := version.NewVersion(sanitizeVersion(peer.Meta.WtVersion))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
constraints, err := version.NewConstraint(">= " + minVer)
|
||||
if err != nil {
|
||||
return false, err
|
||||
n.constraintOnce.Do(func() {
|
||||
n.constraint, n.constraintErr = version.NewConstraint(">= " + sanitizeVersion(n.MinVersion))
|
||||
})
|
||||
if n.constraintErr != nil {
|
||||
return false, n.constraintErr
|
||||
}
|
||||
|
||||
return constraints.Check(peerNBVer), nil
|
||||
return n.constraint.Check(peerNBVer), nil
|
||||
}
|
||||
|
||||
func sanitizeVersion(v string) string {
|
||||
|
||||
Reference in New Issue
Block a user