-
Notifications
You must be signed in to change notification settings - Fork 0
/
authd.go
61 lines (51 loc) · 1.18 KB
/
authd.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
package main
import (
"flag"
"log"
"net"
"github.com/soheilhy/cmux"
"github.com/baffinbay/authservice/audit"
"github.com/baffinbay/authservice/auth"
"github.com/baffinbay/authservice/rpc"
"github.com/baffinbay/authservice/sign"
"github.com/baffinbay/authservice/verify"
"github.com/baffinbay/authservice/webui"
)
var (
listenAddress = flag.String("listen", ":1214", "Address to listen to")
login = flag.String("login", "ldap", "Login method to use")
)
func main() {
flag.Parse()
s, err := net.Listen("tcp", *listenAddress)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
mux := cmux.New(s)
sg := mux.MatchWithWriters(
cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"),
)
sh := mux.Match(cmux.Any())
a := audit.New()
si := sign.New(a)
w := webui.New()
var ab verify.AuthBackend
if *login == "ldap" {
ab = auth.NewLDAP()
} else if *login == "jwt" {
ab, err = auth.NewJWT()
if err != nil {
panic(err)
}
} else if *login == "fake" {
ab = auth.NewFake()
}
v := verify.New(w, si, ab)
r := rpc.New(v)
go r.Serve(sg)
go w.Serve(sh)
err = mux.Serve()
if err != nil {
log.Fatalf("failed to serve mux: %v", err)
}
}