diff options
-rw-r--r-- | README.txt | 5 | ||||
-rw-r--r-- | cmd/git-lfs-authenticate/main.go | 48 | ||||
-rw-r--r-- | cmd/git-lfs-server/main.go | 1 | ||||
-rw-r--r-- | go.mod | 3 |
4 files changed, 57 insertions, 0 deletions
diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..75d9e97 --- /dev/null +++ b/README.txt | |||
@@ -0,0 +1,5 @@ | |||
1 | gitolfs3 | ||
2 | ======== | ||
3 | |||
4 | Yes, this is indeed an integration between Gitolite, Git LFS and Scaleway | ||
5 | Object Storage. | ||
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 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "errors" | ||
5 | "fmt" | ||
6 | "os" | ||
7 | "os/exec" | ||
8 | "strings" | ||
9 | ) | ||
10 | |||
11 | func 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 | |||
18 | func 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 | } | ||
diff --git a/cmd/git-lfs-server/main.go b/cmd/git-lfs-server/main.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/cmd/git-lfs-server/main.go | |||
@@ -0,0 +1 @@ | |||
package main | |||
@@ -0,0 +1,3 @@ | |||
1 | module git.fautchen.eu/gitolfs3 | ||
2 | |||
3 | go 1.21.5 | ||