4f29ce2ee7
* Add CTI API helpers in expr * Allow profiles to have an `on_error` option to profiles Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
36 lines
685 B
Go
36 lines
685 B
Go
package cticlient
|
|
|
|
type FirePaginator struct {
|
|
client *CrowdsecCTIClient
|
|
params FireParams
|
|
currentPage int
|
|
done bool
|
|
}
|
|
|
|
func (p *FirePaginator) Next() ([]FireItem, error) {
|
|
if p.done {
|
|
return nil, nil
|
|
}
|
|
p.params.Page = &p.currentPage
|
|
resp, err := p.client.Fire(p.params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
p.currentPage++
|
|
if resp.Links.Next == nil {
|
|
p.done = true
|
|
}
|
|
return resp.Items, nil
|
|
}
|
|
|
|
func NewFirePaginator(client *CrowdsecCTIClient, params FireParams) *FirePaginator {
|
|
startPage := 1
|
|
if params.Page != nil {
|
|
startPage = *params.Page
|
|
}
|
|
return &FirePaginator{
|
|
client: client,
|
|
params: params,
|
|
currentPage: startPage,
|
|
}
|
|
}
|