mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-03 17:31:13 +01:00
Refactor posture check policy linking logic
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
75ab35563a
commit
7523a9e7be
@ -191,11 +191,10 @@ func (p *Policy) UpgradeAndFix() {
|
||||
}
|
||||
}
|
||||
|
||||
// appliedGroups returns a list of groups applied in the policy, including
|
||||
// both Sources and Destinations from all rules.
|
||||
func (p *Policy) appliedGroups() []string {
|
||||
// ruleGroups returns a list of all groups referenced in the policy's rules,
|
||||
// including sources and destinations.
|
||||
func (p *Policy) ruleGroups() []string {
|
||||
groups := make([]string, 0)
|
||||
|
||||
for _, rule := range p.Rules {
|
||||
groups = append(groups, rule.Sources...)
|
||||
groups = append(groups, rule.Destinations...)
|
||||
@ -405,7 +404,7 @@ func (am *DefaultAccountManager) DeletePolicy(ctx context.Context, accountID, po
|
||||
|
||||
am.StoreEvent(ctx, userID, policy.ID, accountID, activity.PolicyRemoved, policy.EventMeta())
|
||||
|
||||
if anyGroupHasPeers(account, policy.appliedGroups()) {
|
||||
if anyGroupHasPeers(account, policy.ruleGroups()) {
|
||||
am.updateAccountPeers(ctx, account)
|
||||
}
|
||||
|
||||
@ -457,14 +456,14 @@ func (am *DefaultAccountManager) savePolicy(account *Account, policy *Policy) (e
|
||||
account.Policies[i] = policy
|
||||
|
||||
exists = true
|
||||
updateAccountPeers = anyGroupHasPeers(account, p.appliedGroups()) || anyGroupHasPeers(account, policy.appliedGroups())
|
||||
updateAccountPeers = anyGroupHasPeers(account, p.ruleGroups()) || anyGroupHasPeers(account, policy.ruleGroups())
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exists {
|
||||
account.Policies = append(account.Policies, policy)
|
||||
updateAccountPeers = anyGroupHasPeers(account, policy.appliedGroups())
|
||||
updateAccountPeers = anyGroupHasPeers(account, policy.ruleGroups())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -82,8 +82,8 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI
|
||||
|
||||
am.StoreEvent(ctx, userID, postureChecks.ID, accountID, action, postureChecks.EventMeta())
|
||||
|
||||
updateAccountPeers, _ := isPostureCheckLinkedToPolicy(account, postureChecks.ID)
|
||||
if exists && updateAccountPeers {
|
||||
isLinked, linkedPolicy := isPostureCheckLinkedToPolicy(account, postureChecks.ID)
|
||||
if exists && isLinked && anyGroupHasPeers(account, linkedPolicy.ruleGroups()) {
|
||||
am.updateAccountPeers(ctx, account)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user