Skip to content

Commit f46fc88

Browse files
kousumguaypaq
andcommitted
git-annex: add configuration setting [annex].ENABLED (#18)
Fixes #8 Co-authored-by: Mathieu Guay-Paquet <[email protected]>
1 parent 87c04d7 commit f46fc88

File tree

11 files changed

+51
-9
lines changed

11 files changed

+51
-9
lines changed

cmd/serv.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ func runServ(c *cli.Context) error {
220220
}
221221

222222
if verb == gitAnnexShellVerb {
223-
// if !setting.Annex.Enabled { // TODO: https://github.com/neuropoly/gitea/issues/8
224-
if false {
223+
if !setting.Annex.Enabled {
225224
return fail(ctx, "Unknown git command", "git-annex request over SSH denied, git-annex support is disabled")
226225
}
227226

cmd/web.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ func listen(m http.Handler, handleRedirector bool) error {
311311
log.Info("LFS server enabled")
312312
}
313313

314+
if setting.Annex.Enabled {
315+
log.Info("git-annex enabled")
316+
}
317+
314318
var err error
315319
switch setting.Protocol {
316320
case setting.HTTP:

custom/conf/app.example.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,15 @@ LEVEL = Info
25172517
;; override the minio base path if storage type is minio
25182518
;MINIO_BASE_PATH = lfs/
25192519

2520+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2521+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2522+
;[annex]
2523+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2524+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2525+
;;
2526+
;; Whether git-annex is enabled; defaults to false
2527+
;ENABLED = false
2528+
25202529
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25212530
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25222531
;; settings for packages, will override storage setting

modules/setting/annex.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package setting
5+
6+
import (
7+
"code.gitea.io/gitea/modules/log"
8+
)
9+
10+
// Annex represents the configuration for git-annex
11+
var Annex = struct {
12+
Enabled bool `ini:"ENABLED"`
13+
}{}
14+
15+
func loadAnnexFrom(rootCfg ConfigProvider) {
16+
sec := rootCfg.Section("annex")
17+
if err := sec.MapTo(&Annex); err != nil {
18+
log.Fatal("Failed to map Annex settings: %v", err)
19+
}
20+
}

modules/setting/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
149149
loadCamoFrom(cfg)
150150
loadI18nFrom(cfg)
151151
loadGitFrom(cfg)
152+
loadAnnexFrom(cfg)
152153
loadMirrorFrom(cfg)
153154
loadMarkupFrom(cfg)
154155
loadOtherFrom(cfg)

routers/private/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func ServCommand(ctx *context.PrivateContext) {
289289
repo.IsPrivate ||
290290
owner.Visibility.IsPrivate() ||
291291
(user != nil && user.IsRestricted) || // user will be nil if the key is a deploykey
292-
( /*setting.Annex.Enabled && */ len(verbs) > 0 && verbs[0] == "git-annex-shell") || // git-annex has its own permission enforcement, for which we expose results.UserMode
292+
(setting.Annex.Enabled && len(verbs) > 0 && verbs[0] == "git-annex-shell") || // git-annex has its own permission enforcement, for which we expose results.UserMode
293293
setting.Service.RequireSignInView) {
294294
if key.Type == asymkey_model.KeyTypeDeploy {
295295
results.UserMode = deployKey.Mode

tests/integration/git_annex_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ Test that permissions are enforced on git-annex-shell commands.
6161
Along the way, test that uploading, downloading, and deleting all work.
6262
*/
6363
func TestGitAnnexPermissions(t *testing.T) {
64-
/*
65-
// TODO: look into how LFS did this
66-
if !setting.Annex.Enabled {
67-
t.Skip()
68-
}
69-
*/
64+
if !setting.Annex.Enabled {
65+
t.Skip("Skipping since annex support is disabled.")
66+
}
7067

7168
// Each case below is split so that 'clone' is done as
7269
// the repo owner, but 'copy' as the user under test.

tests/mssql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
104104
[lfs]
105105
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mssql/data/lfs
106106

107+
[annex]
108+
ENABLED = true
109+
107110
[packages]
108111
ENABLED = true
109112

tests/mysql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
102102
[lfs]
103103
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mysql/data/lfs
104104

105+
[annex]
106+
ENABLED = true
107+
105108
[packages]
106109
ENABLED = true
107110

tests/pgsql.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
105105
[lfs]
106106
MINIO_BASE_PATH = lfs/
107107

108+
[annex]
109+
ENABLED = true
110+
108111
[attachment]
109112
MINIO_BASE_PATH = attachments/
110113

tests/sqlite.ini.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko
104104
[lfs]
105105
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/data/lfs
106106

107+
[annex]
108+
ENABLED = true
109+
107110
[packages]
108111
ENABLED = true
109112

0 commit comments

Comments
 (0)