08c0b7a2fd
* Refactor error usage from the store level up and add API helpers * Complete API tests * Fix merge errorResponse calls * Remove ensure helpers to allow for custom messages on permission errors * Fix bad import and call * Remove bad user check on auth that was added as part of the main merge * Fix empty list test * Replace deprecated proxy calls to ioutil.ReadAll with io.ReadAll * Add information to the NotFound errors * Add context to all remaining errors and address review comments * Fix linter * Adapt the new card API endpoints to the error refactor * Remove almost all customErrorResponse calls * Add request entity too large to errorResponse and remove customErrorResponse * Fix linter
46 lines
1 KiB
Go
46 lines
1 KiB
Go
package webhook
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/mattermost/focalboard/server/services/config"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
)
|
|
|
|
// NotifyUpdate calls webhooks.
|
|
func (wh *Client) NotifyUpdate(block model.Block) {
|
|
if len(wh.config.WebhookUpdate) < 1 {
|
|
return
|
|
}
|
|
|
|
json, err := json.Marshal(block)
|
|
if err != nil {
|
|
wh.logger.Fatal("NotifyUpdate: json.Marshal", mlog.Err(err))
|
|
}
|
|
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))
|
|
}
|
|
}
|
|
|
|
// Client is a webhook client.
|
|
type Client struct {
|
|
config *config.Configuration
|
|
logger mlog.LoggerIFace
|
|
}
|
|
|
|
// NewClient creates a new Client.
|
|
func NewClient(config *config.Configuration, logger mlog.LoggerIFace) *Client {
|
|
return &Client{
|
|
config: config,
|
|
logger: logger,
|
|
}
|
|
}
|