aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/git-lfs-authenticate
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-29 03:19:25 +0100
committerLibravatar Rutger Broekhoff2023-12-29 03:19:25 +0100
commit0b2fb488e1ccb877f16bad2f413494824f43d9c8 (patch)
treee7f96c4a64f644aff0a9d1659d24dcba83a3015b /cmd/git-lfs-authenticate
downloadgitolfs3-0b2fb488e1ccb877f16bad2f413494824f43d9c8.tar.gz
gitolfs3-0b2fb488e1ccb877f16bad2f413494824f43d9c8.zip
Initial commit
Diffstat (limited to 'cmd/git-lfs-authenticate')
-rw-r--r--cmd/git-lfs-authenticate/main.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/cmd/git-lfs-authenticate/main.go b/cmd/git-lfs-authenticate/main.go
new file mode 100644
index 0000000..7c06a51
--- /dev/null
+++ b/cmd/git-lfs-authenticate/main.go
@@ -0,0 +1,48 @@
1package main
2
3import (
4 "errors"
5 "fmt"
6 "os"
7 "os/exec"
8 "strings"
9)
10
11func die(msg string, args ...any) {
12 fmt.Fprint(os.Stderr, "Error: ")
13 fmt.Fprintf(os.Stderr, msg, args...)
14 fmt.Fprint(os.Stderr, "\n")
15 os.Exit(1)
16}
17
18func main() {
19 if len(os.Args) != 3 {
20 die("expected 2 arguments [path, operation], got %d", len(os.Args)-1)
21 }
22
23 path := strings.TrimPrefix(strings.TrimSuffix(os.Args[1], ".git"), "/")
24 operation := os.Args[2]
25
26 if operation != "download" && operation != "upload" {
27 die("expected operation to be in {upload, download}, got %s", operation)
28 }
29
30 user := os.Getenv("GL_USER")
31 if user == "" {
32 die("expected Gitolite user env (GL_USER) to be set")
33 }
34
35 gitolitePerm := "R"
36 if operation == "upload" {
37 gitolitePerm = "W"
38 }
39
40 // gitolite access -q: returns only exit code
41 cmd := exec.Command("gitolite", "access", "-q", path, user, gitolitePerm)
42 err := cmd.Run()
43 permGranted := err == nil
44 var exitErr *exec.ExitError
45 if err != nil && !errors.As(err, &exitErr) {
46 die("failed to query Gitolite access information")
47 }
48}