+14
-10
hook/setup.go
+14
-10
hook/setup.go
···
36
}
37
}
38
39
// setup hooks for all users
40
//
41
// directory structure is typically like so:
···
43
// did:plc:foobar/repo1
44
// did:plc:foobar/repo2
45
// did:web:barbaz/repo1
46
-
func Setup(opts ...setupOpt) error {
47
-
config := config{}
48
-
for _, o := range opts {
49
-
o(&config)
50
-
}
51
// iterate over all directories in current directory:
52
userDirs, err := os.ReadDir(config.scanPath)
53
if err != nil {
···
65
}
66
67
userPath := filepath.Join(config.scanPath, did)
68
-
if err := setupUser(&config, userPath); err != nil {
69
return err
70
}
71
}
···
74
}
75
76
// setup hooks in /scanpath/did:plc:user
77
-
func setupUser(config *config, userPath string) error {
78
repos, err := os.ReadDir(userPath)
79
if err != nil {
80
return err
···
86
}
87
88
path := filepath.Join(userPath, repo.Name())
89
-
if err := setup(config, path); err != nil {
90
if errors.Is(err, ErrNoGitRepo) {
91
continue
92
}
···
98
}
99
100
// setup hook in /scanpath/did:plc:user/repo
101
-
func setup(config *config, path string) error {
102
if _, err := git.PlainOpen(path); err != nil {
103
return fmt.Errorf("%s: %w", path, ErrNoGitRepo)
104
}
···
121
return nil
122
}
123
124
-
func mkHook(config *config, hookPath string) error {
125
executablePath, err := os.Executable()
126
if err != nil {
127
return err
···
36
}
37
}
38
39
+
func Config(opts ...setupOpt) config {
40
+
config := config{}
41
+
for _, o := range opts {
42
+
o(&config)
43
+
}
44
+
return config
45
+
}
46
+
47
// setup hooks for all users
48
//
49
// directory structure is typically like so:
···
51
// did:plc:foobar/repo1
52
// did:plc:foobar/repo2
53
// did:web:barbaz/repo1
54
+
func Setup(config config) error {
55
// iterate over all directories in current directory:
56
userDirs, err := os.ReadDir(config.scanPath)
57
if err != nil {
···
69
}
70
71
userPath := filepath.Join(config.scanPath, did)
72
+
if err := SetupUser(config, userPath); err != nil {
73
return err
74
}
75
}
···
78
}
79
80
// setup hooks in /scanpath/did:plc:user
81
+
func SetupUser(config config, userPath string) error {
82
repos, err := os.ReadDir(userPath)
83
if err != nil {
84
return err
···
90
}
91
92
path := filepath.Join(userPath, repo.Name())
93
+
if err := SetupRepo(config, path); err != nil {
94
if errors.Is(err, ErrNoGitRepo) {
95
continue
96
}
···
102
}
103
104
// setup hook in /scanpath/did:plc:user/repo
105
+
func SetupRepo(config config, path string) error {
106
if _, err := git.PlainOpen(path); err != nil {
107
return fmt.Errorf("%s: %w", path, ErrNoGitRepo)
108
}
···
125
return nil
126
}
127
128
+
func mkHook(config config, hookPath string) error {
129
executablePath, err := os.Executable()
130
if err != nil {
131
return err
+13
knotserver/routes.go
+13
knotserver/routes.go
···
26
gogit "github.com/go-git/go-git/v5"
27
"github.com/go-git/go-git/v5/plumbing"
28
"github.com/go-git/go-git/v5/plumbing/object"
29
"tangled.sh/tangled.sh/core/knotserver/db"
30
"tangled.sh/tangled.sh/core/knotserver/git"
31
"tangled.sh/tangled.sh/core/patchutil"
···
669
err = h.e.AddRepo(did, ThisServer, relativeRepoPath)
670
if err != nil {
671
l.Error("adding repo permissions", "error", err.Error())
672
writeError(w, err.Error(), http.StatusInternalServerError)
673
return
674
}
···
26
gogit "github.com/go-git/go-git/v5"
27
"github.com/go-git/go-git/v5/plumbing"
28
"github.com/go-git/go-git/v5/plumbing/object"
29
+
"tangled.sh/tangled.sh/core/hook"
30
"tangled.sh/tangled.sh/core/knotserver/db"
31
"tangled.sh/tangled.sh/core/knotserver/git"
32
"tangled.sh/tangled.sh/core/patchutil"
···
670
err = h.e.AddRepo(did, ThisServer, relativeRepoPath)
671
if err != nil {
672
l.Error("adding repo permissions", "error", err.Error())
673
+
writeError(w, err.Error(), http.StatusInternalServerError)
674
+
return
675
+
}
676
+
677
+
err = hook.SetupRepo(hook.Config(
678
+
hook.WithScanPath(h.c.Repo.ScanPath),
679
+
hook.WithInternalApi(h.c.Server.InternalListenAddr),
680
+
),
681
+
repoPath,
682
+
)
683
+
if err != nil {
684
+
l.Error("setting up hooks", "error", err.Error())
685
writeError(w, err.Error(), http.StatusInternalServerError)
686
return
687
}
+2
-2
knotserver/server.go
+2
-2
knotserver/server.go
+1
-1
nix/vm.nix
+1
-1
nix/vm.nix
···
21
g = config.services.tangled-knot.gitUser;
22
in [
23
"d /var/lib/knot 0770 ${u} ${g} - -" # Create the directory first
24
-
"f+ /var/lib/knot/secret 0660 ${u} ${g} - KNOT_SERVER_SECRET=38a7c3237c2a585807e06a5bcfac92eb39442063f3da306b7acb15cfdc51d19d"
25
];
26
services.tangled-knot = {
27
enable = true;
···
21
g = config.services.tangled-knot.gitUser;
22
in [
23
"d /var/lib/knot 0770 ${u} ${g} - -" # Create the directory first
24
+
"f+ /var/lib/knot/secret 0660 ${u} ${g} - KNOT_SERVER_SECRET=40b4db20544e37a12ba3ed7353d4d4421a30e0593385068d2ef85263495794d8"
25
];
26
services.tangled-knot = {
27
enable = true;