1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00
focalboard/server/services/webhook/webhook.go

47 lines
1.0 KiB
Go
Raw Normal View History

2020-10-29 22:09:02 +02:00
package webhook
import (
"bytes"
"encoding/json"
"io"
2020-10-29 22:09:02 +02:00
"net/http"
2021-01-27 00:13:46 +02:00
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/config"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
2020-10-29 22:09:02 +02:00
)
// NotifyUpdate calls webhooks.
func (wh *Client) NotifyUpdate(block *model.Block) {
2020-10-29 22:32:51 +02:00
if len(wh.config.WebhookUpdate) < 1 {
return
}
2020-10-29 22:09:02 +02:00
json, err := json.Marshal(block)
if err != nil {
wh.logger.Fatal("NotifyUpdate: json.Marshal", mlog.Err(err))
2020-10-29 22:09:02 +02:00
}
for _, url := range wh.config.WebhookUpdate {
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(json)) //nolint:gosec
_, _ = io.ReadAll(resp.Body)
resp.Body.Close()
wh.logger.Debug("webhook.NotifyUpdate", mlog.String("url", url))
2020-10-29 22:09:02 +02:00
}
}
// Client is a webhook client.
2020-10-29 22:42:43 +02:00
type Client struct {
2020-10-29 22:09:02 +02:00
config *config.Configuration
logger mlog.LoggerIFace
2020-10-29 22:09:02 +02:00
}
// NewClient creates a new Client.
func NewClient(config *config.Configuration, logger mlog.LoggerIFace) *Client {
2020-10-29 22:42:43 +02:00
return &Client{
2020-10-29 22:09:02 +02:00
config: config,
logger: logger,
2020-10-29 22:09:02 +02:00
}
}