-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (52 loc) · 1.45 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
package main
import (
"net/http"
"os"
"context"
"github.com/rancher/authn-proxy/config"
"github.com/rancher/authn-proxy/impersonation"
"github.com/rancher/authn-proxy/proxy"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Action = run
app.Run(os.Args)
}
func run(c *cli.Context) {
logrus.Infof("Configuring...")
ctx, cancelF := context.WithCancel(context.Background())
defer cancelF()
p, err := proxy.NewReverseProxy(ctx)
if err != nil {
logrus.Fatalf("Failed to get reverse proxy: %v", err)
}
handler, err := impersonation.NewAuthnHeaderHandler(ctx, p)
if err != nil {
logrus.Fatalf("Failed to get impersonation handler: %v", err)
}
conf := config.GetManager(ctx)
if conf.Get("log.level") != "" {
l, err := logrus.ParseLevel(conf.Get("log.level"))
if err == nil {
logrus.SetLevel(l)
}
}
httpsHost := conf.Get("frontend.https.host")
if httpsHost != "" {
go func() {
logrus.Infof("Starting https server listening on %v.", httpsHost)
err := http.ListenAndServeTLS(httpsHost, conf.Get("frontend.ssl.cert.path"), conf.Get("frontend.ssl.key.path"), handler)
logrus.Fatalf("https server exited. Error: %v", err)
}()
}
httpHost := conf.Get("frontend.http.host")
server := &http.Server{
Handler: handler,
Addr: httpHost,
}
logrus.Infof("Starting http server listening on %v.", httpHost)
err = server.ListenAndServe()
logrus.Infof("https server exited. Error: %v", err)
}