mirror of
https://github.com/gluster/glusterd2.git
synced 2026-02-05 12:45:38 +01:00
Implemented wehook/test rest API in glusterd2 which will be called by clients to test webhook connections between all peers in glusterd2 and webhook URL added rest client code to call webhook/test API Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package restclient
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gluster/glusterd2/pkg/api"
|
|
eventsapi "github.com/gluster/glusterd2/plugins/events/api"
|
|
)
|
|
|
|
// WebhookAdd registers webhook to listen to Gluster Events
|
|
func (c *Client) WebhookAdd(url string, token string, secret string) error {
|
|
req := &eventsapi.Webhook{
|
|
URL: url,
|
|
Token: token,
|
|
Secret: secret,
|
|
}
|
|
return c.post("/v1/events/webhook", req, http.StatusOK, nil)
|
|
}
|
|
|
|
// WebhookDelete deletes the webhook
|
|
func (c *Client) WebhookDelete(url string) error {
|
|
req := &eventsapi.WebhookDel{
|
|
URL: url,
|
|
}
|
|
|
|
return c.del("/v1/events/webhook", req, http.StatusNoContent, nil)
|
|
}
|
|
|
|
// Webhooks returns the list of Webhooks listening to Gluster Events
|
|
func (c *Client) Webhooks() (eventsapi.WebhookList, error) {
|
|
var resp eventsapi.WebhookList
|
|
err := c.get("/v1/events/webhook", nil, http.StatusOK, &resp)
|
|
return resp, err
|
|
}
|
|
|
|
// ListEvents returns the list of Gluster Events
|
|
func (c *Client) ListEvents() ([]*api.Event, error) {
|
|
var resp []*api.Event
|
|
err := c.get("/v1/events", nil, http.StatusOK, &resp)
|
|
return resp, err
|
|
}
|
|
|
|
// WebhookTest tests connection between peers and specified URL
|
|
func (c *Client) WebhookTest(url string, token string, secret string) error {
|
|
req := &eventsapi.Webhook{
|
|
URL: url,
|
|
Token: token,
|
|
Secret: secret,
|
|
}
|
|
return c.post("/v1/events/webhook/test", req, http.StatusOK, nil)
|
|
}
|