Skip to content

Commit

Permalink
Format imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga committed Jan 15, 2024
1 parent d855c3f commit 27d9dc5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
15 changes: 10 additions & 5 deletions management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1888,8 +1888,9 @@ paths:
/api/rules:
get:
summary: List all Rules
description: Returns a list of all rules
description: Returns a list of all rules. This will be deprecated in favour of `/api/policies`.
tags: [ Rules ]
deprecated: true
security:
- BearerAuth: [ ]
- TokenAuth: [ ]
Expand All @@ -1912,7 +1913,8 @@ paths:
"$ref": "#/components/responses/internal_error"
post:
summary: Create a Rule
description: Creates a rule
description: Creates a rule. This will be deprecated in favour of `/api/policies`.
deprecated: true
tags: [ Rules ]
security:
- BearerAuth: [ ]
Expand All @@ -1933,7 +1935,8 @@ paths:
/api/rules/{ruleId}:
get:
summary: Retrieve a Rule
description: Get information about a rules
description: Get information about a rules. This will be deprecated in favour of `/api/policies/{policyID}`.
deprecated: true
tags: [ Rules ]
security:
- BearerAuth: [ ]
Expand Down Expand Up @@ -1962,7 +1965,8 @@ paths:
"$ref": "#/components/responses/internal_error"
put:
summary: Update a Rule
description: Update/Replace a rule
description: Update/Replace a rule. This will be deprecated in favour of `/api/policies/{policyID}`.
deprecated: true
tags: [ Rules ]
security:
- BearerAuth: [ ]
Expand Down Expand Up @@ -1997,7 +2001,8 @@ paths:
"$ref": "#/components/responses/internal_error"
delete:
summary: Delete a Rule
description: Delete a rule
description: Delete a rule. This will be deprecated in favour of `/api/policies/{policyID}`.
deprecated: true
tags: [ Rules ]
security:
- BearerAuth: [ ]
Expand Down
29 changes: 29 additions & 0 deletions management/server/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/netbirdio/netbird/management/proto"
"github.com/netbirdio/netbird/management/server/activity"
nbpeer "github.com/netbirdio/netbird/management/server/peer"
"github.com/netbirdio/netbird/management/server/posture"
"github.com/netbirdio/netbird/management/server/status"
)

Expand Down Expand Up @@ -219,6 +220,25 @@ func (a *Account) getPeerConnectionResources(peerID string) ([]*nbpeer.Peer, []*
continue
}

peer, ok := a.Peers[peerID]
if !ok && peer == nil {
continue
}

for _, postureChecksID := range policy.SourcePostureChecks {
postureChecks := getPostureCheck(a, postureChecksID)
if postureChecks == nil {
continue
}

for _, check := range postureChecks.Checks {
if err := check.Check(*peer); err != nil {
log.Debugf("an error occurred on check %s: %s", check.Name(), err.Error())
continue
}
}
}

for _, rule := range policy.Rules {
if !rule.Enabled {
continue
Expand Down Expand Up @@ -512,3 +532,12 @@ func getAllPeersFromGroups(account *Account, groups []string, peerID string) ([]
}
return filteredPeers, peerInGroups
}

func getPostureCheck(account *Account, postureChecksID string) *posture.Checks {
for _, postureChecks := range account.PostureChecks {
if postureChecks.ID == postureChecksID {
return postureChecks
}
}
return nil
}

0 comments on commit 27d9dc5

Please sign in to comment.