From 3db63367ef110e7f4a245cde61471e232e86339c Mon Sep 17 00:00:00 2001 From: Max Resnick Date: Mon, 12 Feb 2024 21:16:48 -0800 Subject: fix: fix up tests and linting --- cmd/main.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'cmd/main.go') 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()) } -- cgit v1.2.3