mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-15 23:28:28 +01:00
Refactor version checks using go-version library
This commit is contained in:
parent
26e4ad7698
commit
3a717368f7
@ -3,6 +3,8 @@ package checks
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
|
||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||
)
|
||||
|
||||
@ -23,20 +25,44 @@ type NBVersionPostureCheck struct {
|
||||
}
|
||||
|
||||
func (n *NBVersionPostureCheck) Check(peer nbpeer.Peer) error {
|
||||
if peer.Meta.WtVersion >= n.MinimumVersionAllowed {
|
||||
peerNBVersion, err := version.NewVersion(peer.Meta.UIVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
constraints, err := version.NewConstraint(">= " + n.MinimumVersionAllowed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if constraints.Check(peerNBVersion) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("peer nb version is not supported")
|
||||
|
||||
return fmt.Errorf("peer nb version is older than minimum allowed version %s", n.MinimumVersionAllowed)
|
||||
}
|
||||
|
||||
type OSVersionPostureCheck struct {
|
||||
Enabled bool
|
||||
MinimumVersionAllowed string
|
||||
|
||||
// TODO: add OS context to prevent using the same version on different OS types
|
||||
}
|
||||
|
||||
func (o *OSVersionPostureCheck) Check(peer nbpeer.Peer) error {
|
||||
if peer.Meta.WtVersion >= o.MinimumVersionAllowed {
|
||||
peerNBVersion, err := version.NewVersion(peer.Meta.UIVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
constraints, err := version.NewConstraint(">= " + o.MinimumVersionAllowed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if constraints.Check(peerNBVersion) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("peer OS version is not supported")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user