mirror of https://github.com/gophish/gophish
Documentation and code cleanup for webhooks
parent
ec8b17238e
commit
8ebdb43469
|
@ -16,20 +16,24 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
||||||
// DefaultTimeoutSeconds is amount of seconds of timeout used by HTTP sender
|
// DefaultTimeoutSeconds is the number of seconds before a timeout occurs
|
||||||
|
// when sending a webhook
|
||||||
DefaultTimeoutSeconds = 10
|
DefaultTimeoutSeconds = 10
|
||||||
|
|
||||||
// MinHTTPStatusErrorCode is the lowest number of an HTTP response which indicates an error
|
// MinHTTPStatusErrorCode is the lower bound of HTTP status codes which
|
||||||
|
// indicate an error occurred
|
||||||
MinHTTPStatusErrorCode = 400
|
MinHTTPStatusErrorCode = 400
|
||||||
|
|
||||||
// SignatureHeader is the name of an HTTP header used to which contains signature of a webhook
|
// SignatureHeader is the name of the HTTP header which contains the
|
||||||
|
// webhook signature
|
||||||
SignatureHeader = "X-Gophish-Signature"
|
SignatureHeader = "X-Gophish-Signature"
|
||||||
|
|
||||||
// Sha256Prefix is the prefix that specifies the hashing algorithm used for signature
|
// Sha256Prefix is the prefix that specifies the hashing algorithm used
|
||||||
|
// for the signature
|
||||||
Sha256Prefix = "sha256"
|
Sha256Prefix = "sha256"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sender defines behaviour of an entity by which webhook is sent
|
// Sender represents a type which can send webhooks to an EndPoint
|
||||||
type Sender interface {
|
type Sender interface {
|
||||||
Send(endPoint EndPoint, data interface{}) error
|
Send(endPoint EndPoint, data interface{}) error
|
||||||
}
|
}
|
||||||
|
@ -47,7 +51,8 @@ var senderInstance = &defaultSender{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndPoint represents and end point to send a webhook to: url and secret by which payload is signed
|
// EndPoint represents a URL to send the webhook to, as well as a secret used
|
||||||
|
// to sign the event
|
||||||
type EndPoint struct {
|
type EndPoint struct {
|
||||||
URL string
|
URL string
|
||||||
Secret string
|
Secret string
|
||||||
|
@ -58,12 +63,12 @@ func Send(endPoint EndPoint, data interface{}) error {
|
||||||
return senderInstance.Send(endPoint, data)
|
return senderInstance.Send(endPoint, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendAll sends data to each of the EndPoints
|
// SendAll sends data to multiple EndPoints
|
||||||
func SendAll(endPoints []EndPoint, data interface{}) {
|
func SendAll(endPoints []EndPoint, data interface{}) {
|
||||||
for _, ept := range endPoints {
|
for _, e := range endPoints {
|
||||||
go func(ept1 EndPoint) {
|
go func(e EndPoint) {
|
||||||
senderInstance.Send(ept1, data)
|
senderInstance.Send(e, data)
|
||||||
}(EndPoint{URL: ept.URL, Secret: ept.Secret})
|
}(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue