aboutsummaryrefslogtreecommitdiff
path: root/cmd/main.go
diff options
context:
space:
mode:
authorMax Resnick <max@ofmax.li>2025-04-08 21:41:59 -0700
committerMax Resnick <max@ofmax.li>2025-05-26 21:57:12 -0700
commit78098f23e9a910f3b37fbd3f7c1939ad10ec40ad (patch)
tree6432695fcc218089a90e1c32f4e1601a14124de4 /cmd/main.go
parent7f3b59980e3b9d8d878aa57f4b01b9d4cc1eab0c (diff)
downloadgo-git-server-78098f23e9a910f3b37fbd3f7c1939ad10ec40ad.tar.gz
feat: refactor of authenticaitonrefactor-authz-scheme
Diffstat (limited to '')
-rw-r--r--cmd/main.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/cmd/main.go b/cmd/main.go
index b679e51..bda8bf6 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -66,18 +66,33 @@ func main() {
if err := adminSvc.InitServer(); err != nil {
slog.Error("error initializing server", "msg", err)
}
- tokens := authz.NewTokenMap()
- err = tokens.LoadTokensFromFile(tokenFilePath)
+ // Load authentication tokens and identity mappings
+ tokens := authz.NewSafeTokenMap()
+ identities := authz.NewIdentityMap()
+
+ // Load tokens from CSV file
+ tokenMap, identityMap, err := authz.LoadTokensFromFile(tokenFilePath)
if err != nil {
- slog.Error("error generating token", slog.Any("error", err))
+ slog.Error("error loading tokens", slog.Any("error", err))
os.Exit(1)
}
+
+ // Update the token map with loaded values
+ for id, hash := range tokenMap {
+ tokens.Set(id, hash)
+ }
+
+ // Copy identity mappings
+ for id, name := range identityMap.IDToName {
+ identities.Register(id, name)
+ }
+
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))
+ mux := authz.Authentication(tokens, identities, authz.Authorization(adminSvc, router))
server := &http.Server{
Addr: addr,
ReadHeaderTimeout: 5 * time.Second,