Skip to content

Commit

Permalink
notifier: Rename HTTP to Webhook Notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M committed Dec 17, 2015
1 parent 2ea86c5 commit f4a4d41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/Notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions notifier/notifiers/http.go → notifier/notifiers/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit f4a4d41

Please sign in to comment.