This repository has been archived by the owner on Jun 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
69 lines (63 loc) · 1.61 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
package main
import (
"fmt"
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/rancher/webhook-service/drivers"
"github.com/rancher/webhook-service/service"
"github.com/urfave/cli"
)
var VERSION = "v0.0.0-dev"
func main() {
app := cli.NewApp()
app.Name = "webhook-service"
app.Version = VERSION
app.Usage = "You need help!"
app.Action = StartWebhook
app.Commands = []cli.Command{}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rsa-public-key-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing RSA public key",
),
},
cli.StringFlag{
Name: "rsa-private-key-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing RSA private key",
),
},
cli.StringFlag{
Name: "rsa-public-key-contents",
Usage: fmt.Sprintf(
"An alternative to rsa-public-key-file. Specify the contents of the key.",
),
EnvVar: "RSA_PUBLIC_KEY_CONTENTS",
},
cli.StringFlag{
Name: "rsa-private-key-contents",
Usage: fmt.Sprintf(
"An alternative to rsa-private-key-file. Specify the contents of the key.",
),
EnvVar: "RSA_PRIVATE_KEY_CONTENTS",
},
}
app.Run(os.Args)
}
func StartWebhook(c *cli.Context) {
drivers.RegisterDrivers()
privateKey, publicKey, err := service.GetKeys(c)
if err != nil {
log.Fatal("rsa-private-key-file or rsa-public-key-file not provided, halting")
}
rh := &service.RouteHandler{
PrivateKey: privateKey,
PublicKey: publicKey,
ClientFactory: &service.ClientFactory{},
}
router := service.NewRouter(rh)
log.Infof("Webhook service listening on 8085")
log.Fatal(http.ListenAndServe(":8085", router))
}