Skip to content

Commit 56b1e05

Browse files
authored
papi: check if decision is allowlisted before adding it (#4196)
1 parent 19e2a37 commit 56b1e05

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pkg/apiserver/papi_cmd.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ func AlertCmd(ctx context.Context, message *Message, p *Papi, sync bool) error {
104104
}
105105

106106
log.Infof("Received order %s from PAPI (%d decisions)", alert.UUID, len(alert.Decisions))
107+
decisionsToKeep := make([]*models.Decision, 0)
108+
for _, decision := range alert.Decisions {
109+
if decision.Value == nil {
110+
continue
111+
}
112+
isAllowlisted, reason, err := p.DBClient.IsAllowlisted(ctx, *decision.Value)
113+
if err != nil {
114+
log.Errorf("Failed to check if decision '%s' is allowlisted: %s", *decision.Value, err)
115+
// keep the decision in case of error during allowlist check
116+
decisionsToKeep = append(decisionsToKeep, decision)
117+
continue
118+
}
119+
if isAllowlisted {
120+
log.Infof("Decision '%s' is allowlisted, removing it (%s)", *decision.Value, reason)
121+
continue
122+
}
123+
decisionsToKeep = append(decisionsToKeep, decision)
124+
}
125+
alert.Decisions = decisionsToKeep
126+
127+
if len(alert.Decisions) == 0 {
128+
log.Infof("All decisions are allowlisted for alert %s, skipping alert creation", alert.UUID)
129+
return nil
130+
}
107131

108132
/*Fix the alert with missing mandatory items*/
109133
if alert.StartAt == nil || *alert.StartAt == "" {

0 commit comments

Comments
 (0)