Skip to content

Commit 3e02519

Browse files
authored
Merge pull request #36 from gitopia/release-v1.5.0
git credential helper for git lfs auth
2 parents 1223322 + 4113563 commit 3e02519

File tree

18 files changed

+1160
-797
lines changed

18 files changed

+1160
-797
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes will be documented here.
44

5+
## [v1.5.0] - 2023-05-17
6+
7+
- git credential helper for git lfs
8+
- Use git cli instead of go-git for fetch/push
9+
- Common http basic auth for both git push and lfs
10+
- Refactor wallets
11+
- Support fee grant
12+
- Upgrade gitopia version to v2.0.1
13+
514
## [v1.4.0] - 2023-02-22
615

716
- Upgrade gitopia version to v1.3.0

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ build_tags := $(strip $(build_tags))
3030
BUILD_FLAGS := -tags "$(build_tags) $(GITOPIA_ENV)"
3131

3232
appname := git-remote-gitopia
33-
version := 1.4.0
33+
version := $(shell echo $(shell git describe --tags) | sed 's/^v//')
3434

3535
build = GOOS=$(1) GOARCH=$(2) go build $(BUILD_FLAGS) -o build/$(appname)$(3) ./cmd/git-remote-gitopia && \
36-
GOOS=$(1) GOARCH=$(2) go build $(BUILD_FLAGS) -o build/git-gitopia$(3) ./cmd/git-gitopia
37-
tar = cd build && tar -cvzf $(appname)_$(version)_$(1)_$(2).tar.gz $(appname)$(3) git-gitopia$(3) && \
38-
rm $(appname)$(3) && rm git-gitopia$(3)
39-
zip = cd build && zip $(appname)_$(version)_$(1)_$(2).zip $(appname)$(3) git-gitopia$(3) && \
40-
rm $(appname)$(3) && rm git-gitopia$(3)
36+
GOOS=$(1) GOARCH=$(2) go build $(BUILD_FLAGS) -o build/git-gitopia$(3) ./cmd/git-gitopia && \
37+
GOOS=$(1) GOARCH=$(2) go build $(BUILD_FLAGS) -o build/git-credential-gitopia$(3) ./cmd/git-credential-gitopia
38+
tar = cd build && tar -cvzf $(appname)_$(version)_$(1)_$(2).tar.gz $(appname)$(3) git-gitopia$(3) git-credential-gitopia$(3) && \
39+
rm $(appname)$(3) && rm git-gitopia$(3) && rm git-credential-gitopia$(3)
40+
zip = cd build && zip $(appname)_$(version)_$(1)_$(2).zip $(appname)$(3) git-gitopia$(3) git-credential-gitopia$(3) && \
41+
rm $(appname)$(3) && rm git-gitopia$(3) && rm git-credential-gitopia$(3)
4142

4243
.PHONY: build
4344

44-
all: windows darwin linux git_release_tar_gz git_release_zip
45+
all: darwin linux git_release_tar_gz git_release_zip
4546

4647
clean:
4748
rm -rf build/
@@ -99,6 +100,8 @@ install: go.sum
99100
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/git-remote-gitopia
100101
@echo "--> Installing git-gitopia"
101102
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/git-gitopia
103+
@echo "--> Installing git-credential-gitopia"
104+
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/git-credential-gitopia
102105

103106
go.sum: go.mod
104107
@echo "--> Ensure dependencies have not been modified"

cmd/git-credential-gitopia/main.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"io"
7+
"os"
8+
"strings"
9+
10+
"github.com/gitopia/git-remote-gitopia/core/wallet"
11+
"github.com/pkg/errors"
12+
log "github.com/sirupsen/logrus"
13+
)
14+
15+
const (
16+
actionGet = "get"
17+
actionStore = "store"
18+
actionErase = "erase"
19+
)
20+
21+
func main() {
22+
var action string
23+
//nolint:gomnd // Just a count of cli arguments, no need to make a constant
24+
if len(os.Args) == 2 {
25+
action = os.Args[1]
26+
}
27+
28+
switch action {
29+
30+
case actionGet:
31+
handleGetAction()
32+
33+
case actionErase, actionStore:
34+
// Defined action but unsupported by this provider
35+
return
36+
37+
default:
38+
log.Fatalf("Unsupported action %q", action)
39+
40+
}
41+
}
42+
43+
func handleGetAction() {
44+
values, err := readInput(os.Stdin)
45+
if err != nil {
46+
log.WithError(err).Fatal("Unable to parse input values")
47+
}
48+
49+
if proto := values["protocol"]; proto != "https" {
50+
log.Debugf("Unsupported protocol %q", proto)
51+
return
52+
}
53+
54+
wallet, err := wallet.InitWallet()
55+
if err != nil {
56+
log.Debugf(err.Error())
57+
return
58+
}
59+
60+
signature, err := wallet.SignData([]byte(values["host"]))
61+
if err != nil {
62+
log.Debugf(err.Error())
63+
return
64+
}
65+
66+
values["username"] = wallet.Address()
67+
values["password"] = signature
68+
69+
fmt.Fprintln(os.Stdout, strings.Join(MapToList(values), "\n"))
70+
}
71+
72+
func readInput(input io.Reader) (map[string]string, error) {
73+
var (
74+
lines []string
75+
scanner = bufio.NewScanner(input)
76+
)
77+
78+
for scanner.Scan() {
79+
text := strings.TrimSpace(scanner.Text())
80+
81+
if text == "" {
82+
break
83+
}
84+
85+
lines = append(lines, text)
86+
}
87+
88+
return ListToMap(lines), errors.Wrap(scanner.Err(), "Unable to read input")
89+
}

cmd/git-credential-gitopia/util.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// ListToMap converts a list of strings in format KEY=VALUE into a map
8+
func ListToMap(list []string) map[string]string {
9+
out := map[string]string{}
10+
for _, entry := range list {
11+
if len(entry) == 0 || entry[0] == '#' {
12+
continue
13+
}
14+
15+
parts := strings.SplitN(entry, "=", 2)
16+
if len(parts) == 1 {
17+
// No value, set to empty string
18+
parts = append(parts, "")
19+
}
20+
out[parts[0]] = strings.Trim(parts[1], "\"")
21+
}
22+
return out
23+
}
24+
25+
// MapToList converts a map into a list of strings in format KEY=VALUE
26+
func MapToList(envMap map[string]string) []string {
27+
out := []string{}
28+
for k, v := range envMap {
29+
out = append(out, k+"="+v)
30+
}
31+
return out
32+
}

cmd/git-remote-gitopia/errors.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)