-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook.go
41 lines (32 loc) · 867 Bytes
/
webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package metact
import (
"fmt"
"github.com/labstack/echo/v4"
)
type Notification struct {
Entry []struct {
ID string `json:"id"`
Time int `json:"time"`
Changes []struct {
Field string `json:"field"`
Value Certificate `json:"value"`
} `json:"changes"`
} `json:"entry"`
Object string `json:"object"`
}
func (ct *MetaCT) WebHookCertificates(c echo.Context) ([]Certificate, error) {
var notification Notification
if err := c.Bind(¬ification); err != nil {
return nil, fmt.Errorf("error parsing payload: %v", err)
}
if notification.Object != "certificate_transparency" {
return nil, fmt.Errorf("invalid object: %s", notification.Object)
}
certs := []Certificate{}
for _, entry := range notification.Entry {
for _, change := range entry.Changes {
certs = append(certs, change.Value)
}
}
return certs, nil
}