MCPcopy
hub / github.com/crowdsecurity/crowdsec / PullOnce

Method PullOnce

pkg/apiserver/papi.go:212–234  ·  view source on GitHub ↗
(ctx context.Context, since time.Time, sync bool)

Source from the content-addressed store, hash-verified

210}
211
212func (p *Papi) PullOnce(ctx context.Context, since time.Time, sync bool) error {
213 events, err := p.Client.PullOnce(ctx, since)
214 if err != nil {
215 return err
216 }
217
218 reversedEvents := reverse(events) // PAPI sends events in the reverse order, which is not an issue when pulling them in real time, but here we need the correct order
219 eventsCount := len(events)
220 p.Logger.Infof("received %d events", eventsCount)
221
222 for i, event := range reversedEvents {
223 if err := p.handleEvent(ctx, event, sync); err != nil {
224 p.Logger.WithField("request-id", event.RequestId).Errorf("failed to handle event: %s", err)
225 }
226
227 p.Logger.Debugf("handled event %d/%d", i, eventsCount)
228 }
229
230 p.Logger.Debugf("finished handling events")
231 // Don't update the timestamp in DB, as a "real" LAPI might be running
232 // Worst case, crowdsec will receive a few duplicated events and will discard them
233 return nil
234}
235
236// Pull is the long polling client for real-time decisions from PAPI
237func (p *Papi) Pull(ctx context.Context) error {

Callers 1

syncMethod · 0.45

Calls 2

handleEventMethod · 0.95
reverseFunction · 0.85

Tested by

no test coverage detected