-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Toby Padilla
committed
Oct 3, 2021
1 parent
c09197a
commit 73edc31
Showing
3 changed files
with
55 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,54 @@ | ||
package config | ||
|
||
import ( | ||
"log" | ||
|
||
gm "github.com/charmbracelet/wish/git" | ||
"github.com/gliderlabs/ssh" | ||
) | ||
|
||
func (cfg *Config) AuthRepo(repo string, pk ssh.PublicKey) gm.AccessLevel { | ||
// TODO: check yaml for access rules | ||
return gm.ReadWriteAccess | ||
return cfg.accessForKey(repo, pk) | ||
} | ||
|
||
func (cfg *Config) PasswordHandler(ctx ssh.Context, password string) bool { | ||
return (cfg.AnonAccess != "no-access") && cfg.AllowNoKeys | ||
} | ||
|
||
func (cfg *Config) PublicKeyHandler(ctx ssh.Context, pk ssh.PublicKey) bool { | ||
// TODO: check yaml for access rules | ||
if cfg.accessForKey("", pk) == gm.NoAccess { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (cfg *Config) accessForKey(repo string, pk ssh.PublicKey) gm.AccessLevel { | ||
for _, u := range cfg.Users { | ||
apk, _, _, _, err := ssh.ParseAuthorizedKey([]byte(u.PublicKey)) | ||
if err != nil { | ||
log.Printf("error: malformed authorized key: '%s'", u.PublicKey) | ||
return gm.NoAccess | ||
} | ||
if ssh.KeysEqual(pk, apk) { | ||
if u.Admin { | ||
return gm.AdminAccess | ||
} | ||
for _, r := range u.CollabRepos { | ||
if repo == r { | ||
return gm.ReadWriteAccess | ||
} | ||
} | ||
return gm.ReadOnlyAccess | ||
} | ||
} | ||
switch cfg.AnonAccess { | ||
case "no-access": | ||
return gm.NoAccess | ||
case "read-only": | ||
return gm.ReadOnlyAccess | ||
case "read-write": | ||
return gm.ReadWriteAccess | ||
default: | ||
return gm.NoAccess | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters