Skip to content

Commit

Permalink
git-annex: add configuration setting [annex].ENABLED (#18)
Browse files Browse the repository at this point in the history
Fixes #8

Co-authored-by: Mathieu Guay-Paquet <[email protected]>
  • Loading branch information
2 people authored and actions-user committed Nov 9, 2023
1 parent 53c0438 commit 081a4bd
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ func runServ(c *cli.Context) error {
}

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

Expand Down
4 changes: 4 additions & 0 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ func listen(m http.Handler, handleRedirector bool) error {
log.Info("LFS server enabled")
}

if setting.Annex.Enabled {
log.Info("git-annex enabled")
}

var err error
switch setting.Protocol {
case setting.HTTP:
Expand Down
9 changes: 9 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,15 @@ LEVEL = Info
;; override the minio base path if storage type is minio
;MINIO_BASE_PATH = lfs/

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;[annex]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Whether git-annex is enabled; defaults to false
;ENABLED = false

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; settings for packages, will override storage setting
Expand Down
20 changes: 20 additions & 0 deletions modules/setting/annex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package setting

import (
"code.gitea.io/gitea/modules/log"
)

// Annex represents the configuration for git-annex
var Annex = struct {
Enabled bool `ini:"ENABLED"`
}{}

func loadAnnexFrom(rootCfg ConfigProvider) {
sec := rootCfg.Section("annex")
if err := sec.MapTo(&Annex); err != nil {
log.Fatal("Failed to map Annex settings: %v", err)
}
}
1 change: 1 addition & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
loadCamoFrom(cfg)
loadI18nFrom(cfg)
loadGitFrom(cfg)
loadAnnexFrom(cfg)
loadMirrorFrom(cfg)
loadMarkupFrom(cfg)
loadOtherFrom(cfg)
Expand Down
2 changes: 1 addition & 1 deletion routers/private/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func ServCommand(ctx *context.PrivateContext) {
repo.IsPrivate ||
owner.Visibility.IsPrivate() ||
(user != nil && user.IsRestricted) || // user will be nil if the key is a deploykey
( /*setting.Annex.Enabled && */ len(verbs) > 0 && verbs[0] == "git-annex-shell") || // git-annex has its own permission enforcement, for which we expose results.UserMode
(setting.Annex.Enabled && len(verbs) > 0 && verbs[0] == "git-annex-shell") || // git-annex has its own permission enforcement, for which we expose results.UserMode
setting.Service.RequireSignInView) {
if key.Type == asymkey_model.KeyTypeDeploy {
results.UserMode = deployKey.Mode
Expand Down
9 changes: 3 additions & 6 deletions tests/integration/git_annex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ Test that permissions are enforced on git-annex-shell commands.
Along the way, test that uploading, downloading, and deleting all work.
*/
func TestGitAnnexPermissions(t *testing.T) {
/*
// TODO: look into how LFS did this
if !setting.Annex.Enabled {
t.Skip()
}
*/
if !setting.Annex.Enabled {
t.Skip("Skipping since annex support is disabled.")
}

// Each case below is split so that 'clone' is done as
// the repo owner, but 'copy' as the user under test.
Expand Down
3 changes: 3 additions & 0 deletions tests/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
[lfs]
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mssql/data/lfs

[annex]
ENABLED = true

[packages]
ENABLED = true

Expand Down
3 changes: 3 additions & 0 deletions tests/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
[lfs]
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-mysql/data/lfs

[annex]
ENABLED = true

[packages]
ENABLED = true

Expand Down
3 changes: 3 additions & 0 deletions tests/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
[lfs]
MINIO_BASE_PATH = lfs/

[annex]
ENABLED = true

[attachment]
MINIO_BASE_PATH = attachments/

Expand Down
3 changes: 3 additions & 0 deletions tests/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko
[lfs]
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/data/lfs

[annex]
ENABLED = true

[packages]
ENABLED = true

Expand Down

0 comments on commit 081a4bd

Please sign in to comment.