Skip to content

Commit

Permalink
Remove the enabled field, as posture check will now automatically be …
Browse files Browse the repository at this point in the history
…activated by default when attaching to a policy
  • Loading branch information
bcmmbaga committed Jan 15, 2024
1 parent 92c09e2 commit d855c3f
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 56 deletions.
5 changes: 0 additions & 5 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,11 @@ components:
description: Posture check for the version of NetBird
type: object
properties:
enabled:
description: NetBird's version check status
type: boolean
example: false
min_version:
description: Minimum acceptable NetBird version
type: string
example: "0.25.0"
required:
- enabled
- min_version
PostureCheckUpdate:
type: object
Expand Down
3 changes: 0 additions & 3 deletions management/server/http/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions management/server/http/posture_checks_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func (p *PostureChecksHandler) savePostureChecks(

if nbVersionCheck := req.Checks.NbVersionCheck; nbVersionCheck != nil {
postureChecks.Checks = append(postureChecks.Checks, &posture.NBVersionCheck{
Enabled: nbVersionCheck.Enabled,
MinVersion: nbVersionCheck.MinVersion,
})

Expand Down Expand Up @@ -219,7 +218,6 @@ func toPostureChecksResponse(postureChecks *posture.Checks) *api.PostureCheck {
case posture.NBVersionCheckName:
versionCheck := check.(*posture.NBVersionCheck)
checks.NbVersionCheck = &api.NBVersionCheck{
Enabled: versionCheck.Enabled,
MinVersion: versionCheck.MinVersion,
}
}
Expand Down
22 changes: 4 additions & 18 deletions management/server/http/posture_checks_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func TestGetPostureCheck(t *testing.T) {
Name: "name",
Checks: []posture.Check{
&posture.NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
},
Expand Down Expand Up @@ -175,9 +174,7 @@ func TestPostureCheckUpdate(t *testing.T) {
"description": "default",
"checks": {
"nb_version_check": {
"enabled": true,
"min_version": "1.2.3",
"max_version": "2.0.0"
"min_version": "1.2.3"
}
}
}`)),
Expand All @@ -189,7 +186,6 @@ func TestPostureCheckUpdate(t *testing.T) {
Description: str("default"),
Checks: api.Checks{
NbVersionCheck: &api.NBVersionCheck{
Enabled: true,
MinVersion: "1.2.3",
},
},
Expand All @@ -204,7 +200,6 @@ func TestPostureCheckUpdate(t *testing.T) {
"name": "default",
"checks": {
"non_existing_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
Expand All @@ -220,7 +215,6 @@ func TestPostureCheckUpdate(t *testing.T) {
[]byte(`{
"checks": {
"nb_version_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
Expand All @@ -236,9 +230,7 @@ func TestPostureCheckUpdate(t *testing.T) {
[]byte(`{
"name": "default",
"checks": {
"nb_version_check": {
"enabled": true,
}
"nb_version_check": {}
}
}`)),
expectedStatus: http.StatusBadRequest,
Expand All @@ -253,7 +245,6 @@ func TestPostureCheckUpdate(t *testing.T) {
"name": "default",
"checks": {
"nb_version_check": {
"enabled": true,
"min_version": "1.9.0"
}
}
Expand All @@ -266,7 +257,6 @@ func TestPostureCheckUpdate(t *testing.T) {
Description: str(""),
Checks: api.Checks{
NbVersionCheck: &api.NBVersionCheck{
Enabled: true,
MinVersion: "1.9.0",
},
},
Expand All @@ -281,7 +271,6 @@ func TestPostureCheckUpdate(t *testing.T) {
"name": "default",
"checks": {
"non_existing_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
Expand All @@ -297,7 +286,7 @@ func TestPostureCheckUpdate(t *testing.T) {
[]byte(`{
"checks": {
"nb_version_check": {
"enabled": true,
"min_version": "1.2.0"
}
}
}`)),
Expand All @@ -312,9 +301,7 @@ func TestPostureCheckUpdate(t *testing.T) {
[]byte(`{
"name": "default",
"checks": {
"nb_version_check": {
"enabled": false,
}
"nb_version_check": {}
}
}`)),
expectedStatus: http.StatusBadRequest,
Expand All @@ -327,7 +314,6 @@ func TestPostureCheckUpdate(t *testing.T) {
Name: "postureCheck",
Checks: []posture.Check{
&posture.NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
},
Expand Down
4 changes: 0 additions & 4 deletions management/server/posture/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestChecks_MarshalJSON(t *testing.T) {
AccountID: "acc1",
Checks: []Check{
&NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
},
Expand All @@ -34,7 +33,6 @@ func TestChecks_MarshalJSON(t *testing.T) {
"Description": "desc1",
"Checks": {
"NBVersionCheck": {
"Enabled": true,
"MinVersion": "1.0.0"
}
}
Expand All @@ -60,7 +58,6 @@ func TestChecks_MarshalJSON(t *testing.T) {
"Description": "",
"Checks": {
"NBVersionCheck": {
"Enabled": false,
"MinVersion": ""
}
}
Expand Down Expand Up @@ -112,7 +109,6 @@ func TestChecks_UnmarshalJSON(t *testing.T) {
Description: "desc1",
Checks: []Check{
&NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
},
Expand Down
5 changes: 0 additions & 5 deletions management/server/posture/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ import (
)

type NBVersionCheck struct {
Enabled bool
MinVersion string
}

var _ Check = (*NBVersionCheck)(nil)

func (n *NBVersionCheck) Check(peer nbpeer.Peer) error {
if !n.Enabled {
return nil
}

peerNBVersion, err := version.NewVersion(peer.Meta.WtVersion)
if err != nil {
return err
Expand Down
19 changes: 0 additions & 19 deletions management/server/posture/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
wantErr: false,
Expand All @@ -36,7 +35,6 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "2.0",
},
wantErr: false,
Expand All @@ -49,7 +47,6 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "2.0",
},
wantErr: false,
Expand All @@ -62,7 +59,6 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
wantErr: true,
Expand All @@ -75,24 +71,10 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "0.2",
},
wantErr: true,
},
{
name: "Older Peer NB version With Check Disabled",
input: peer.Peer{
Meta: peer.PeerSystemMeta{
WtVersion: "0.0.9",
},
},
check: NBVersionCheck{
Enabled: false,
MinVersion: "1.0.0",
},
wantErr: false,
},
{
name: "Invalid Peer NB version",
input: peer.Peer{
Expand All @@ -101,7 +83,6 @@ func TestNBVersionCheck_Check(t *testing.T) {
},
},
check: NBVersionCheck{
Enabled: true,
MinVersion: "1.0.0",
},
wantErr: true,
Expand Down

0 comments on commit d855c3f

Please sign in to comment.