From 82d78bda83e4753c5a969922db8ddb7b0cca532a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 21 Nov 2022 17:14:04 -0500 Subject: [PATCH] fix(config): use repo path in logs --- config/auth.go | 42 ++++++++++++++++++++++-------------------- config/git.go | 4 ++-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/config/auth.go b/config/auth.go index 4319eeb2063342af1fc9106dce2bf9e8c0b954d8..f977e410046d93b286d9122e5225dc467d047a1b 100644 --- a/config/auth.go +++ b/config/auth.go @@ -86,29 +86,31 @@ func (cfg *Config) accessForKey(repo string, pk ssh.PublicKey) gm.AccessLevel { anon := cfg.anonAccessLevel() private := cfg.isPrivate(repo) // Find user - for _, user := range cfg.Users { - for _, k := range user.PublicKeys { - apk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(strings.TrimSpace(k))) - if err != nil { - log.Printf("error: malformed authorized key: '%s'", k) - return gm.NoAccess - } - if ssh.KeysEqual(pk, apk) { - if user.Admin { - return gm.AdminAccess + if pk != nil { + for _, user := range cfg.Users { + for _, k := range user.PublicKeys { + apk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(strings.TrimSpace(k))) + if err != nil { + log.Printf("error: malformed authorized key: '%s'", k) + return gm.NoAccess } - u := user - if cfg.isCollab(repo, &u) { - if anon > gm.ReadWriteAccess { - return anon + if ssh.KeysEqual(pk, apk) { + if user.Admin { + return gm.AdminAccess } - return gm.ReadWriteAccess - } - if !private { - if anon > gm.ReadOnlyAccess { - return anon + u := user + if cfg.isCollab(repo, &u) { + if anon > gm.ReadWriteAccess { + return anon + } + return gm.ReadWriteAccess + } + if !private { + if anon > gm.ReadOnlyAccess { + return anon + } + return gm.ReadOnlyAccess } - return gm.ReadOnlyAccess } } } diff --git a/config/git.go b/config/git.go index 73b3edcb1a619c9bd937430060ad3013df032738..00e2fac85d8d1dfa6ffb4ff77e65978e139c973d 100644 --- a/config/git.go +++ b/config/git.go @@ -237,9 +237,9 @@ func (rs *RepoSource) LoadRepo(name string) error { return err } if !r.IsBare() { - log.Printf("warning: %q is not a bare repository", rp) + log.Printf("warning: %q is not a bare repository", r.Path()) } else if r.IsBare() && !strings.HasSuffix(rp, ".git") { - log.Printf("warning: %q should be renamed to %q", rp, rp+".git") + log.Printf("warning: %q should be renamed to %q", r.Path(), r.Path()+".git") } rs.repos[name] = r return nil