exclude 'lists' too if we exclude CAPI (#2474)

This commit is contained in:
Thibault "bui" Koechlin 2023-09-19 13:56:22 +02:00 committed by GitHub
parent d5b6f2974b
commit 4c08e1e68c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,10 +28,10 @@ import (
)
const (
paginationSize = 100 // used to queryAlert to avoid 'too many SQL variable'
defaultLimit = 100 // default limit of element to returns when query alerts
bulkSize = 50 // bulk size when create alerts
maxLockRetries = 10 // how many times to retry a bulk operation when sqlite3.ErrBusy is encountered
paginationSize = 100 // used to queryAlert to avoid 'too many SQL variable'
defaultLimit = 100 // default limit of element to returns when query alerts
bulkSize = 50 // bulk size when create alerts
maxLockRetries = 10 // how many times to retry a bulk operation when sqlite3.ErrBusy is encountered
)
func formatAlertCN(source models.Source) string {
@ -485,7 +485,6 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in
return alertRef.ID, inserted, deleted, nil
}
func (c *Client) createDecisionChunk(simulated bool, stopAtTime time.Time, decisions []*models.Decision) ([]*ent.Decision, error) {
decisionCreate := make([]*ent.DecisionCreate, len(decisions))
@ -532,7 +531,6 @@ func (c *Client) createDecisionChunk(simulated bool, stopAtTime time.Time, decis
return ret, nil
}
func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts []*models.Alert) ([]string, error) {
alertBuilders := make([]*ent.AlertCreate, len(alerts))
alertDecisions := make([][]*ent.Decision, len(alerts))
@ -737,7 +735,6 @@ func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts [
return ret, nil
}
func (c *Client) CreateAlert(machineID string, alertList []*models.Alert) ([]string, error) {
var owner *ent.Machine
var err error
@ -863,6 +860,8 @@ func AlertPredicatesFromFilter(filter map[string][]string) ([]predicate.Alert, e
case "include_capi": //allows to exclude one or more specific origins
if value[0] == "false" {
predicates = append(predicates, alert.Not(alert.HasDecisionsWith(decision.OriginEQ(types.CAPIOrigin))))
predicates = append(predicates, alert.Not(alert.HasDecisionsWith(decision.OriginEQ(types.ListOrigin))))
} else if value[0] != "true" {
log.Errorf("Invalid bool '%s' for include_capi", value[0])
}