Skip to content

Commit

Permalink
Split git-receive-pack and git-upload-pack into separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
belak committed Mar 13, 2024
1 parent 9570113 commit 8d48e90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ssh_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func cmdNotFound(ctx context.Context, s ssh.Session, cmd []string) int {
return 1
}

func (serv *Server) cmdGitReceivePack(ctx context.Context, s ssh.Session, cmd []string) int {
return serv.cmdRepoAction(ctx, s, cmd, AccessLevelWrite)
}

func (serv *Server) cmdGitUploadPack(ctx context.Context, s ssh.Session, cmd []string) int {
return serv.cmdRepoAction(ctx, s, cmd, AccessLevelRead)
}

func (serv *Server) cmdRepoAction(ctx context.Context, s ssh.Session, cmd []string, access AccessLevel) int {
if len(cmd) != 2 {
_ = writeStringFmt(s.Stderr(), "Missing repo name argument\r\n")
Expand Down
4 changes: 2 additions & 2 deletions ssh_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func (serv *Server) handleSession(s ssh.Session) {
case "whoami":
exit = cmdWhoami(ctx, s, cmd)
case "git-receive-pack":
exit = serv.cmdRepoAction(ctx, s, cmd, AccessLevelWrite)
exit = serv.cmdGitReceivePack(ctx, s, cmd)
case "git-upload-pack":
exit = serv.cmdRepoAction(ctx, s, cmd, AccessLevelRead)
exit = serv.cmdGitUploadPack(ctx, s, cmd)
default:
exit = cmdNotFound(ctx, s, cmd)
}
Expand Down

0 comments on commit 8d48e90

Please sign in to comment.