Skip to content

Commit e6d952d

Browse files
update serv command to recognize group ids in urls
1 parent 33e4f2b commit e6d952d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

cmd/serv.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,17 @@ func runServ(ctx context.Context, c *cli.Command) error {
200200

201201
repoPath := strings.TrimPrefix(sshCmdArgs[1], "/")
202202
repoPathFields := strings.SplitN(repoPath, "/", 2)
203+
rawGroup, _, _ := strings.Cut(repoPathFields[1], "/")
204+
var groupID int64
203205
if len(repoPathFields) != 2 {
204-
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
206+
if len(repoPathFields) == 3 {
207+
groupID, err = strconv.ParseInt(rawGroup, 10, 64)
208+
if err != nil {
209+
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
210+
}
211+
} else {
212+
return fail(ctx, "Invalid repository path", "Invalid repository path: %v", repoPath)
213+
}
205214
}
206215

207216
username := repoPathFields[0]
@@ -248,16 +257,16 @@ func runServ(ctx context.Context, c *cli.Command) error {
248257

249258
requestedMode := getAccessMode(verb, lfsVerb)
250259

251-
results, extra := private.ServCommand(ctx, keyID, username, reponame, requestedMode, verb, lfsVerb)
260+
results, extra := private.ServCommand(ctx, keyID, username, reponame, groupID, requestedMode, verb, lfsVerb)
252261
if extra.HasError() {
253262
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
254263
}
255264

256265
// because the original repoPath maybe redirected, we need to use the returned actual repository information
257266
if results.IsWiki {
258-
repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName)
267+
repoPath = repo_model.RelativeWikiPath(results.OwnerName, results.RepoName, groupID)
259268
} else {
260-
repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName)
269+
repoPath = repo_model.RelativePath(results.OwnerName, results.RepoName, groupID)
261270
}
262271

263272
// LFS SSH protocol

modules/private/serv.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ type ServCommandResults struct {
4646
}
4747

4848
// ServCommand preps for a serv call
49-
func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) {
50-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s?mode=%d",
49+
func ServCommand(ctx context.Context, keyID int64, ownerName, repoName string, groupID int64, mode perm.AccessMode, verb, lfsVerb string) (*ServCommandResults, ResponseExtra) {
50+
var groupSegment string
51+
if groupID > 0 {
52+
groupSegment = fmt.Sprintf("%d/", groupID)
53+
}
54+
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/command/%d/%s/%s%s?mode=%d",
5155
keyID,
5256
url.PathEscape(ownerName),
57+
groupSegment,
5358
url.PathEscape(repoName),
5459
mode,
5560
)

0 commit comments

Comments
 (0)