This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (59 loc) · 1.62 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
67
68
69
70
package main
import (
"net/http"
log "github.com/sirupsen/logrus"
)
func main() {
// Create a function to handle panic and exit gracefully
defer func() {
if err := recover(); err != nil {
log.Fatal("Could not recover, exiting")
}
}()
config, err := NewConfig()
if err != nil {
log.Fatal(err)
}
tlsBroker, err := TLSConfigBroker(config)
if err != nil {
log.Fatal(err)
}
tlsProxy, err := TLSConfigProxy(config)
if err != nil {
log.Fatal(err)
}
err = checkS3Bucket(config.S3)
if err != nil {
log.Fatal(err)
}
messenger := NewAMQPMessenger(config.Broker, tlsBroker)
log.Debug("messenger acquired ", messenger)
var pubkeys map[string][]byte
auth := NewValidateFromToken(pubkeys)
auth.pubkeys = make(map[string][]byte)
// Load keys for JWT verification
if config.Server.jwtpubkeyurl != "" {
if err := auth.getjwtpubkey(config.Server.jwtpubkeyurl); err != nil {
log.Panicf("Error while getting key %s: %v", config.Server.jwtpubkeyurl, err)
}
}
if config.Server.jwtpubkeypath != "" {
if err := auth.getjwtkey(config.Server.jwtpubkeypath); err != nil {
log.Panicf("Error while getting key %s: %v", config.Server.jwtpubkeypath, err)
}
}
proxy := NewProxy(config.S3, auth, messenger, tlsProxy)
log.Debug("got the proxy ", proxy)
http.Handle("/", proxy)
hc := NewHealthCheck(8001, config.S3, config.Broker, tlsProxy)
go hc.RunHealthChecks()
if config.Server.cert != "" && config.Server.key != "" {
if e := http.ListenAndServeTLS(":8000", config.Server.cert, config.Server.key, nil); e != nil {
panic(e)
}
} else {
if e := http.ListenAndServe(":8000", nil); e != nil {
panic(e)
}
}
}