From 0b2fb488e1ccb877f16bad2f413494824f43d9c8 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 29 Dec 2023 03:19:25 +0100 Subject: Initial commit --- README.txt | 5 +++++ cmd/git-lfs-authenticate/main.go | 48 ++++++++++++++++++++++++++++++++++++++++ cmd/git-lfs-server/main.go | 1 + go.mod | 3 +++ 4 files changed, 57 insertions(+) create mode 100644 README.txt create mode 100644 cmd/git-lfs-authenticate/main.go create mode 100644 cmd/git-lfs-server/main.go create mode 100644 go.mod diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..75d9e97 --- /dev/null +++ b/README.txt @@ -0,0 +1,5 @@ +gitolfs3 +======== + +Yes, this is indeed an integration between Gitolite, Git LFS and Scaleway +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 @@ +package main + +import ( + "errors" + "fmt" + "os" + "os/exec" + "strings" +) + +func die(msg string, args ...any) { + fmt.Fprint(os.Stderr, "Error: ") + fmt.Fprintf(os.Stderr, msg, args...) + fmt.Fprint(os.Stderr, "\n") + os.Exit(1) +} + +func main() { + if len(os.Args) != 3 { + die("expected 2 arguments [path, operation], got %d", len(os.Args)-1) + } + + path := strings.TrimPrefix(strings.TrimSuffix(os.Args[1], ".git"), "/") + operation := os.Args[2] + + if operation != "download" && operation != "upload" { + die("expected operation to be in {upload, download}, got %s", operation) + } + + user := os.Getenv("GL_USER") + if user == "" { + die("expected Gitolite user env (GL_USER) to be set") + } + + gitolitePerm := "R" + if operation == "upload" { + gitolitePerm = "W" + } + + // gitolite access -q: returns only exit code + cmd := exec.Command("gitolite", "access", "-q", path, user, gitolitePerm) + err := cmd.Run() + permGranted := err == nil + var exitErr *exec.ExitError + if err != nil && !errors.As(err, &exitErr) { + die("failed to query Gitolite access information") + } +} 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 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e5c27f4 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.fautchen.eu/gitolfs3 + +go 1.21.5 -- cgit v1.2.3