From f4a4d417e7fee46add6f32d6284a9a6a8b9ce10d Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Thu, 17 Dec 2015 13:37:03 -0500 Subject: [PATCH] notifier: Rename HTTP to Webhook Notifier --- docs/Notifications.md | 2 +- notifier/notifiers/{http.go => webhook.go} | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) rename notifier/notifiers/{http.go => webhook.go} (83%) diff --git a/docs/Notifications.md b/docs/Notifications.md index 9ef0d4d1..a91d4705 100644 --- a/docs/Notifications.md +++ b/docs/Notifications.md @@ -2,7 +2,7 @@ This tool can send notifications to external services when specific events happen, such as vulnerability updates. -For now, it only supports transmitting them to an HTTP endpoint using POST requests, but it can be extended quite easily by registering a new Notifier kind. +For now, it only supports transmitting them to an webhook endpoint using HTTP POST requests, but it can be extended quite easily by registering a new Notifier kind. To enable the notification system, you simply have to specify the appropriate configuration. See the [example configuration](../config.example.yaml). # Types of notifications diff --git a/notifier/notifiers/http.go b/notifier/notifiers/webhook.go similarity index 83% rename from notifier/notifiers/http.go rename to notifier/notifiers/webhook.go index e57567f8..c726f29c 100644 --- a/notifier/notifiers/http.go +++ b/notifier/notifiers/webhook.go @@ -32,14 +32,14 @@ import ( "github.com/coreos/clair/notifier" ) -// A HTTP notifier dispatches notifications to an HTTP endpoint. -type HTTP struct { +// A WebhookNotifier dispatches notifications to a webhook endpoint. +type WebhookNotifier struct { endpoint string client *http.Client } -// A HTTPConfiguration represents the configuration of an HTTP notifier. -type HTTPConfiguration struct { +// A WebhookNotifierConfiguration represents the configuration of a WebhookNotifier. +type WebhookNotifierConfiguration struct { Endpoint string ServerName string CertFile string @@ -48,12 +48,12 @@ type HTTPConfiguration struct { } func init() { - notifier.RegisterNotifier("http", &HTTP{}) + notifier.RegisterNotifier("webhook", &WebhookNotifier{}) } -func (h *HTTP) Configure(config *config.NotifierConfig) (bool, error) { +func (h *WebhookNotifier) Configure(config *config.NotifierConfig) (bool, error) { // Get configuration - var httpConfig HTTPConfiguration + var httpConfig WebhookNotifierConfiguration if config == nil { return false, nil } @@ -92,14 +92,14 @@ func (h *HTTP) Configure(config *config.NotifierConfig) (bool, error) { return true, nil } -func (h *HTTP) Send(notification *notifier.Notification) error { +func (h *WebhookNotifier) Send(notification *notifier.Notification) error { // Marshal notification. jsonNotification, err := json.Marshal(notification) if err != nil { return fmt.Errorf("could not marshal: %s", err) } - // Send notification over HTTP. + // Send notification via HTTP POST. resp, err := h.client.Post(h.endpoint, "application/json", bytes.NewBuffer(jsonNotification)) if err != nil || resp == nil || (resp.StatusCode != 200 && resp.StatusCode != 201) { if resp != nil { @@ -112,11 +112,11 @@ func (h *HTTP) Send(notification *notifier.Notification) error { return nil } -// loadTLSClientConfig initializes a *tls.Config using the given HTTPConfiguration. +// loadTLSClientConfig initializes a *tls.Config using the given WebhookNotifierConfiguration. // // If no certificates are given, (nil, nil) is returned. // The CA certificate is optional and falls back to the system default. -func loadTLSClientConfig(cfg *HTTPConfiguration) (*tls.Config, error) { +func loadTLSClientConfig(cfg *WebhookNotifierConfiguration) (*tls.Config, error) { if cfg.CertFile == "" || cfg.KeyFile == "" { return nil, nil }