Refactor group, ns group, policy and posture checks

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga
2024-10-21 17:12:19 +03:00
parent 8b61ffa78f
commit 070e1dd890
4 changed files with 30 additions and 3 deletions

View File

@@ -68,8 +68,7 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI
am.StoreEvent(ctx, userID, postureChecks.ID, accountID, action, postureChecks.EventMeta())
isLinked, linkedPolicy := isPostureCheckLinkedToPolicy(account, postureChecks.ID)
if exists && isLinked && anyGroupHasPeers(account, linkedPolicy.ruleGroups()) {
if arePostureCheckChangesAffectingPeers(account, postureChecks.ID, exists) {
am.updateAccountPeers(ctx, account)
}
@@ -224,3 +223,16 @@ func isPostureCheckLinkedToPolicy(account *Account, postureChecksID string) (boo
}
return false, nil
}
// arePostureCheckChangesAffectingPeers checks if the changes in posture checks are affecting peers.
func arePostureCheckChangesAffectingPeers(account *Account, postureCheckID string, exists bool) bool {
if !exists {
return false
}
isLinked, linkedPolicy := isPostureCheckLinkedToPolicy(account, postureCheckID)
if !isLinked {
return false
}
return anyGroupHasPeers(account, linkedPolicy.ruleGroups())
}