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