crowdsec/pkg/apiclient/signal.go
Thibault "bui" Koechlin 6e92da76ad
lapi to capi : allow push of tainted/custom/manual decisions (#1154)
* add console command to control signal sharing
* modify metrics endpoint to add lastpush

Co-authored-by: alteredCoder <kevin@crowdsec.net>
2022-01-13 16:46:16 +01:00

34 lines
871 B
Go

package apiclient
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/crowdsecurity/crowdsec/pkg/models"
"github.com/pkg/errors"
)
type SignalService service
func (s *SignalService) Add(ctx context.Context, signals *models.AddSignalsRequest) (interface{}, *Response, error) {
var response interface{}
u := fmt.Sprintf("%s/signals", s.client.URLPrefix)
req, err := s.client.NewRequest("POST", u, &signals)
if err != nil {
return nil, nil, errors.Wrap(err, "while building request")
}
resp, err := s.client.Do(ctx, req, &response)
if err != nil {
return nil, resp, errors.Wrap(err, "while performing request")
}
if resp.Response.StatusCode != 200 {
log.Warnf("Signal push response : http %s", resp.Response.Status)
} else {
log.Debugf("Signal push response : http %s", resp.Response.Status)
}
return &response, resp, nil
}