forked from bomoko/lagoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (65 loc) · 1.89 KB
/
Copy pathmain.go
File metadata and controls
75 lines (65 loc) · 1.89 KB
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
71
72
73
74
75
package main
/*
this is a simple wrestic snapshot webhook handler for lagoon
https://nesv.github.io/golang/2014/02/25/worker-queues-in-go.html
workerqueues maybe in the event rabbit goes away
*/
import (
"log"
"net/http"
"os"
"github.com/amazeeio/lagoon/services/backup-handler/internal/handler"
)
var (
httpListenPort = os.Getenv("HTTP_LISTEN_PORT")
)
func main() {
// we want all of these vars, else fail
if len(os.Getenv("RABBITMQ_ADDRESS")) == 0 {
log.Fatalln("RABBITMQ_ADDRESS not set")
}
if len(os.Getenv("RABBITMQ_PORT")) == 0 {
log.Fatalln("RABBITMQ_PORT not set")
}
if len(os.Getenv("RABBITMQ_USERNAME")) == 0 {
log.Fatalln("RABBITMQ_USERNAME not set")
}
if len(os.Getenv("RABBITMQ_PASSWORD")) == 0 {
log.Fatalln("RABBITMQ_PASSWORD not set")
}
if len(os.Getenv("JWT_SECRET")) == 0 {
log.Fatalln("JWT_SECRET not set")
}
if len(os.Getenv("JWT_AUDIENCE")) == 0 {
log.Fatalln("JWT_AUDIENCE not set")
}
if len(os.Getenv("GRAPHQL_ENDPOINT")) == 0 {
log.Fatalln("GRAPHQL_ENDPOINT not set")
}
if len(os.Getenv("HTTP_LISTEN_PORT")) == 0 {
httpListenPort = "3000"
}
// configure the backup handler settings
broker := handler.RabbitBroker{
Hostname: os.Getenv("RABBITMQ_ADDRESS"),
Username: os.Getenv("RABBITMQ_USERNAME"),
Password: os.Getenv("RABBITMQ_PASSWORD"),
Port: os.Getenv("RABBITMQ_PORT"),
QueueName: "lagoon-webhooks:queue",
ExchangeName: "lagoon-webhooks",
}
graphQL := handler.GraphQLEndpoint{
Endpoint: os.Getenv("GRAPHQL_ENDPOINT"),
TokenSigningKey: os.Getenv("JWT_SECRET"),
JWTAudience: os.Getenv("JWT_AUDIENCE"),
}
// set up the backup handler
backupHandler, err := handler.NewBackupHandler(broker, graphQL)
if err != nil {
panic(err)
}
log.Println("backup-handler running")
// handle the webhook requests
http.HandleFunc("/", backupHandler.WebhookHandler)
http.ListenAndServe(":"+httpListenPort, nil)
}