Skip to content

Commit

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

Fixes #8

Co-authored-by: Mathieu Guay-Paquet <mathieu.guaypaquet@gmail.com>
  • Loading branch information
2 people authored and actions-user committed Sep 20, 2022
1 parent ace51f8 commit 571c912
Show file tree
Hide file tree
Showing 11 changed files with 52 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 @@ -183,8 +183,7 @@ func runServ(c *cli.Context) error {
verb := words[0]
repoPath := words[1]
if verb == gitAnnexShellVerb {
//if !setting.Annex.Enabled { // TODO: https://github.com/neuropoly/gitea/issues/8
if false {
if !setting.Annex.Enabled {
return fail("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 @@ -227,6 +227,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 @@ -2360,6 +2360,15 @@ ROUTER = console
;; Where your lfs files reside, default is data/lfs.
;PATH = data/lfs

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; settings for packages, will override storage setting
Expand Down
21 changes: 21 additions & 0 deletions modules/setting/annex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package setting

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

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

func newAnnex() {
sec := Cfg.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 @@ -1070,6 +1070,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
API.SwaggerURL = u.String()

newGit()
newAnnex()

newMirror()

Expand Down
2 changes: 1 addition & 1 deletion routers/private/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,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 @@ -54,12 +54,9 @@ func doCreateRemoteAnnexRepository(t *testing.T, u *url.URL, ctx APITestContext,
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/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ SSH_TRUSTED_USER_CA_KEYS = ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCb4DC1dMFnJ6pXW
[lfs]
MINIO_BASE_PATH = lfs/

[annex]
ENABLED = true

[attachment]
MINIO_BASE_PATH = attachments/

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

[annex]
ENABLED = true

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions tests/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.h
[lfs]
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-pgsql/data/lfs

[annex]
ENABLED = true

[packages]
ENABLED = true
3 changes: 3 additions & 0 deletions tests/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,8 @@ JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko
[lfs]
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/data/lfs

[annex]
ENABLED = true

[packages]
ENABLED = true

0 comments on commit 571c912

Please sign in to comment.