Skip to content

Commit

Permalink
modules/lfstransfer: add a backend and runner
Browse files Browse the repository at this point in the history
Also add handler in runServ()

The protocol lib supports locking but the backend does not,
as neither does Gitea. Support can be added later and the
capability advertised.
  • Loading branch information
ConcurrentCrab committed Jun 30, 2024
1 parent cf762f6 commit d6d422f
Show file tree
Hide file tree
Showing 4 changed files with 474 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfstransfer"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/pprof"
"code.gitea.io/gitea/modules/private"
Expand All @@ -40,6 +41,7 @@ const (
verbUploadArchive = "git-upload-archive"
verbReceivePack = "git-receive-pack"
verbLfsAuthenticate = "git-lfs-authenticate"
verbLfsTransfer = "git-lfs-transfer"
)

// CmdServ represents the available serv sub-command.
Expand Down Expand Up @@ -83,9 +85,11 @@ var (
verbUploadArchive: true,
verbReceivePack: true,
verbLfsAuthenticate: true,
verbLfsTransfer: true,
}
allowedCommandsLfs = map[string]bool{
verbLfsAuthenticate: true,
verbLfsTransfer: true,
}
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
)
Expand Down Expand Up @@ -138,7 +142,7 @@ func getAccessMode(verb string, lfsVerb string) perm.AccessMode {
return perm.AccessModeRead
case verbReceivePack:
return perm.AccessModeWrite
case verbLfsAuthenticate:
case verbLfsAuthenticate, verbLfsTransfer:
switch lfsVerb {
case "upload":
return perm.AccessModeWrite
Expand Down Expand Up @@ -297,6 +301,15 @@ func runServ(c *cli.Context) error {
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
}

// LFS SSH protocol
if verb == verbLfsTransfer {
token, err := getLFSAuthToken(ctx, lfsVerb, results)
if err != nil {
return err
}
return lfstransfer.Main(ctx, repoPath, lfsVerb, token)
}

// LFS token authentication
if verb == verbLfsAuthenticate {
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))
Expand Down
Loading

0 comments on commit d6d422f

Please sign in to comment.