-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
66 lines (58 loc) · 1.4 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"log"
"net/http"
"github.com/brigadecore/brigade-dockerhub-gateway/internal/webhooks"
libHTTP "github.com/brigadecore/brigade-foundations/http"
"github.com/brigadecore/brigade-foundations/signals"
"github.com/brigadecore/brigade-foundations/version"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/gorilla/mux"
)
func main() {
log.Printf(
"Starting Brigade Docker Hub Gateway -- version %s -- commit %s",
version.Version(),
version.Commit(),
)
var webhooksService webhooks.Service
{
address, token, opts, err := apiClientConfig()
if err != nil {
log.Fatal(err)
}
webhooksService = webhooks.NewService(
sdk.NewEventsClient(address, token, &opts),
)
}
var tokenFilter libHTTP.Filter
{
config, err := tokenFilterConfig()
if err != nil {
log.Fatal(err)
}
tokenFilter = webhooks.NewTokenFilter(config)
}
var server libHTTP.Server
{
handler, err := webhooks.NewHandler(webhooksService)
if err != nil {
log.Fatal(err)
}
router := mux.NewRouter()
router.StrictSlash(true)
router.Handle(
"/events",
tokenFilter.Decorate(handler.ServeHTTP),
).Methods(http.MethodPost)
router.HandleFunc("/healthz", libHTTP.Healthz).Methods(http.MethodGet)
serverConfig, err := serverConfig()
if err != nil {
log.Fatal(err)
}
server = libHTTP.NewServer(router, &serverConfig)
}
log.Println(
server.ListenAndServe(signals.Context()),
)
}