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
|
package main
import (
"flag"
"fmt"
"log"
"net/http"
"time"
"git.ofmax.li/go-git-server/internal/admin"
"git.ofmax.li/go-git-server/internal/authz"
"git.ofmax.li/go-git-server/internal/git"
)
var (
reposDir = *flag.String("r", "./repos", "Directory containing git repositories")
mgmtRepo = *flag.Bool("a", true, "mgmt repo used for configuration")
backendCommand = *flag.String("c", "git http-backend", "CGI binary to execute")
addr = *flag.String("l", ":8080", "Address/port to listen on")
modelPath = *flag.String("m", "./auth_model.ini", "Authentication model")
policyPath = *flag.String("p", "./policy.csv", "auth policy")
serverConfigPath = *flag.String("s", "/gitserver.yaml", "serverconfig path")
newToken = *flag.Bool("t", false, "make a new token")
// TODO what was my intent here?
// updatePolicies = flag.Bool("u", false, "update policies")
)
func main() {
flag.Parse()
if newToken {
token, hash, err := authz.GenerateNewToken()
if err != nil {
log.Fatal(err)
}
fmt.Printf("token: %s\nhash: %s\n", token, hash)
return
}
adminSvc := admin.NewService(modelPath, policyPath, serverConfigPath, reposDir, mgmtRepo)
adminSvc.InitServer()
tokens := authz.NewTokenMap()
err := tokens.LoadTokensFromFile("./tokens.csv")
if err != nil {
log.Fatal(err)
}
router := http.NewServeMux()
// TODO we don't want to use a global
// de-reference args
router.Handle("/mgmt/", admin.Hooks(adminSvc, git.GitHttpBackendHandler(reposDir, backendCommand)))
router.Handle("/", git.GitHttpBackendHandler(reposDir, backendCommand))
mux := authz.Authentication(tokens, authz.Authorization(adminSvc, router))
server := &http.Server{
Addr: addr,
ReadHeaderTimeout: 5 * time.Second,
Handler: mux,
}
log.Fatal(server.ListenAndServe())
}
|