2020-11-30 09:37:17 +00:00
|
|
|
package apiclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-08-16 07:46:10 +00:00
|
|
|
"net/http"
|
2022-01-13 15:46:16 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2022-08-16 07:46:10 +00:00
|
|
|
req, err := s.client.NewRequest(http.MethodPost, u, &signals)
|
2020-11-30 09:37:17 +00:00
|
|
|
if err != nil {
|
2023-06-22 13:01:34 +00:00
|
|
|
return nil, nil, fmt.Errorf("while building request: %w", err)
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.client.Do(ctx, req, &response)
|
|
|
|
if err != nil {
|
2023-06-22 13:01:34 +00:00
|
|
|
return nil, resp, fmt.Errorf("while performing request: %w", err)
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2022-09-06 11:55:03 +00:00
|
|
|
if resp.Response.StatusCode != http.StatusOK {
|
2022-01-13 15:46:16 +00:00
|
|
|
log.Warnf("Signal push response : http %s", resp.Response.Status)
|
|
|
|
} else {
|
|
|
|
log.Debugf("Signal push response : http %s", resp.Response.Status)
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
return &response, resp, nil
|
|
|
|
}
|