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