notifier: Rename HTTP to Webhook Notifier
This commit is contained in:
parent
2ea86c53f3
commit
f4a4d417e7
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This tool can send notifications to external services when specific events happen, such as vulnerability updates.
|
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).
|
To enable the notification system, you simply have to specify the appropriate configuration. See the [example configuration](../config.example.yaml).
|
||||||
|
|
||||||
# Types of notifications
|
# Types of notifications
|
||||||
|
@ -32,14 +32,14 @@ import (
|
|||||||
"github.com/coreos/clair/notifier"
|
"github.com/coreos/clair/notifier"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A HTTP notifier dispatches notifications to an HTTP endpoint.
|
// A WebhookNotifier dispatches notifications to a webhook endpoint.
|
||||||
type HTTP struct {
|
type WebhookNotifier struct {
|
||||||
endpoint string
|
endpoint string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// A HTTPConfiguration represents the configuration of an HTTP notifier.
|
// A WebhookNotifierConfiguration represents the configuration of a WebhookNotifier.
|
||||||
type HTTPConfiguration struct {
|
type WebhookNotifierConfiguration struct {
|
||||||
Endpoint string
|
Endpoint string
|
||||||
ServerName string
|
ServerName string
|
||||||
CertFile string
|
CertFile string
|
||||||
@ -48,12 +48,12 @@ type HTTPConfiguration struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
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
|
// Get configuration
|
||||||
var httpConfig HTTPConfiguration
|
var httpConfig WebhookNotifierConfiguration
|
||||||
if config == nil {
|
if config == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@ -92,14 +92,14 @@ func (h *HTTP) Configure(config *config.NotifierConfig) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HTTP) Send(notification *notifier.Notification) error {
|
func (h *WebhookNotifier) Send(notification *notifier.Notification) error {
|
||||||
// Marshal notification.
|
// Marshal notification.
|
||||||
jsonNotification, err := json.Marshal(notification)
|
jsonNotification, err := json.Marshal(notification)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not marshal: %s", err)
|
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))
|
resp, err := h.client.Post(h.endpoint, "application/json", bytes.NewBuffer(jsonNotification))
|
||||||
if err != nil || resp == nil || (resp.StatusCode != 200 && resp.StatusCode != 201) {
|
if err != nil || resp == nil || (resp.StatusCode != 200 && resp.StatusCode != 201) {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
@ -112,11 +112,11 @@ func (h *HTTP) Send(notification *notifier.Notification) error {
|
|||||||
return nil
|
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.
|
// If no certificates are given, (nil, nil) is returned.
|
||||||
// The CA certificate is optional and falls back to the system default.
|
// 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 == "" {
|
if cfg.CertFile == "" || cfg.KeyFile == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user