2024-02-20 09:59:56 +01:00
|
|
|
package posture
|
|
|
|
|
|
|
|
import (
|
2024-07-03 11:33:02 +02:00
|
|
|
"context"
|
2024-06-13 13:24:24 +02:00
|
|
|
"fmt"
|
|
|
|
|
2024-02-20 09:59:56 +01:00
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NBVersionCheck struct {
|
|
|
|
MinVersion string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Check = (*NBVersionCheck)(nil)
|
|
|
|
|
2024-07-03 11:33:02 +02:00
|
|
|
func (n *NBVersionCheck) Check(ctx context.Context, peer nbpeer.Peer) (bool, error) {
|
2024-02-20 09:59:56 +01:00
|
|
|
peerNBVersion, err := version.NewVersion(peer.Meta.WtVersion)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
constraints, err := version.NewConstraint(">= " + n.MinVersion)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if constraints.Check(peerNBVersion) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2024-07-03 11:33:02 +02:00
|
|
|
log.WithContext(ctx).Debugf("peer %s NB version %s is older than minimum allowed version %s",
|
2024-02-20 09:59:56 +01:00
|
|
|
peer.ID, peer.Meta.WtVersion, n.MinVersion)
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NBVersionCheck) Name() string {
|
|
|
|
return NBVersionCheckName
|
|
|
|
}
|
2024-06-13 13:24:24 +02:00
|
|
|
|
|
|
|
func (n *NBVersionCheck) Validate() error {
|
|
|
|
if n.MinVersion == "" {
|
|
|
|
return fmt.Errorf("%s minimum version shouldn't be empty", n.Name())
|
|
|
|
}
|
|
|
|
if !isVersionValid(n.MinVersion) {
|
|
|
|
return fmt.Errorf("%s version: %s is not valid", n.Name(), n.MinVersion)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|