diff options
| author | Max Resnick <max@ofmax.li> | 2024-02-12 21:16:48 -0800 |
|---|---|---|
| committer | Max Resnick <max@ofmax.li> | 2024-02-17 22:28:39 -0800 |
| commit | 3db63367ef110e7f4a245cde61471e232e86339c (patch) | |
| tree | 7be4be99ab5953f8d7beb1c613b0d0bc64db6c65 /cmd | |
| parent | 45a9f3814c14b41b93e47ae4cbc3f50c34d94991 (diff) | |
| download | go-git-server-3db63367ef110e7f4a245cde61471e232e86339c.tar.gz | |
fix: fix up tests and linting
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/main.go | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/cmd/main.go b/cmd/main.go index bf3697d..a0f007b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "time" "git.ofmax.li/go-git-server/internal/admin" "git.ofmax.li/go-git-server/internal/authz" @@ -12,20 +13,21 @@ import ( ) 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") - updatePolicies = flag.Bool("u", false, "update policies") + 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 { + if newToken { token, hash, err := authz.GenerateNewToken() if err != nil { log.Fatal(err) @@ -33,7 +35,7 @@ func main() { fmt.Printf("token: %s\nhash: %s\n", token, hash) return } - adminSvc := admin.NewService(*modelPath, *policyPath, *serverConfigPath, *reposDir, *mgmtRepo) + adminSvc := admin.NewService(modelPath, policyPath, serverConfigPath, reposDir, mgmtRepo) adminSvc.InitServer() tokens := authz.NewTokenMap() err := tokens.LoadTokensFromFile("./tokens.csv") @@ -43,8 +45,13 @@ func main() { router := http.NewServeMux() // TODO we don't want to use a global // de-reference args - router.Handle("/mgmt/", admin.AdminHooks(adminSvc, git.GitHttpBackendHandler(*reposDir, *backendCommand))) - router.Handle("/", git.GitHttpBackendHandler(*reposDir, *backendCommand)) + router.Handle("/mgmt/", admin.Hooks(adminSvc, git.GitHttpBackendHandler(reposDir, backendCommand))) + router.Handle("/", git.GitHttpBackendHandler(reposDir, backendCommand)) mux := authz.Authentication(tokens, authz.Authorization(adminSvc, router)) - log.Fatal(http.ListenAndServe(":8080", mux)) + server := &http.Server{ + Addr: addr, + ReadHeaderTimeout: 5 * time.Second, + Handler: mux, + } + log.Fatal(server.ListenAndServe()) } |