Skip to content

Commit a549c79

Browse files
committed
Remove gitserver host from default config and add liveness check
1 parent 3a3c518 commit a549c79

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

cmd/git-gitopia/lfs/init.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func InitCommand() *cobra.Command {
6060
}
6161
}
6262
gitServerHost, _ := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
63-
if gitServerHost == "" {
63+
if gitServerHost == "" || !api.CheckGitServerHostLiveness(gitServerHost) {
6464
gitServerHost = api.GetBestGitServerHost(grpcHost)
6565
if gitServerHost != "" {
6666
if err := api.SetConfiguredGitServerHost(gitServerHost); err != nil {
@@ -90,10 +90,6 @@ func InitCommand() *cobra.Command {
9090
}
9191

9292
remoteRepository := *res.Repository
93-
gitServerHost, _ = config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
94-
if gitServerHost == "" {
95-
gitServerHost = config.GitServerHost
96-
}
9793
lfsURL := fmt.Sprintf("%v/%v.git", gitServerHost, remoteRepository.Id)
9894

9995
c = core.GitCommand("git", "config",

cmd/git-remote-gitopia/gitopia.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (h *GitopiaHandler) Initialize(remote *core.Remote) error {
6969
}
7070

7171
gitServerHost, _ := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
72-
if gitServerHost == "" {
72+
if gitServerHost == "" || !api.CheckGitServerHostLiveness(gitServerHost) {
7373
gitServerHost = api.GetBestGitServerHost(grpcHost)
7474
if gitServerHost != "" {
7575
if err := api.SetConfiguredGitServerHost(gitServerHost); err != nil {
@@ -148,9 +148,9 @@ func (h *GitopiaHandler) List(remote *core.Remote, forPush bool) ([]string, erro
148148
}
149149

150150
func (h *GitopiaHandler) Fetch(remote *core.Remote, refsToFetch []core.RefToFetch) error {
151-
gitServerHost, _ := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
152-
if gitServerHost == "" {
153-
gitServerHost = config.GitServerHost
151+
gitServerHost, err := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
152+
if err != nil {
153+
return err
154154
}
155155
remoteURL := fmt.Sprintf("%v/%v.git", gitServerHost, h.remoteRepository.Id)
156156

@@ -228,9 +228,9 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
228228
return nil, fmt.Errorf("fatal: you don't have write permissions to this repository")
229229
}
230230

231-
gitServerHost, _ := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
232-
if gitServerHost == "" {
233-
gitServerHost = config.GitServerHost
231+
gitServerHost, err := config.GitConfigGet(config.GitopiaConfigGitServerHostOption)
232+
if err != nil {
233+
return nil, err
234234
}
235235
remoteURL := fmt.Sprintf("%v/%v.git", gitServerHost, h.remoteRepository.Id)
236236

config/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ func LoadGitConfig() error {
3636
if res, err := GitConfigGet(GitopiaConfigChainIdOption); err == nil {
3737
ChainId = res
3838
}
39-
if res, err := GitConfigGet(GitopiaConfigGitServerHostOption); err == nil {
40-
GitServerHost = res
41-
}
4239
if res, err := GitConfigGet(GitopiaConfigGasPricesOption); err == nil {
4340
GasPrices = res
4441
}

config/config_dev.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package config
44

55
var (
66
ChainId = "gitopia"
7-
GitServerHost = "https://server.devnet.gitopia.com"
87
GasPrices = "0.001ulore"
98
FeeGranterAddr = ""
109
Denom = "ulore"

config/config_prod.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package config
44

55
var (
66
ChainId = "gitopia"
7-
GitServerHost = "https://server.gitopia.com"
87
GasPrices = "0.001ulore"
98
FeeGranterAddr = "gitopia13ashgc6j5xle4m47kqyn5psavq0u3klmscfxql"
109
Denom = "ulore"

config/config_testing.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package config
44

55
var (
66
ChainId = "localgitopia"
7-
GitServerHost = "http://localhost:5001"
87
GasPrices = "0.001ulore"
98
FeeGranterAddr = "gitopia12sjhqc3rqgvu3zpg8ekmwl005rp4ys58ekqg89"
109
Denom = "ulore"

core/api/gitserver.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import (
77
"github.com/gitopia/git-remote-gitopia/core"
88
)
99

10+
func CheckGitServerHostLiveness(host string) bool {
11+
res, err := http.Get(host + "/healthz")
12+
if err != nil {
13+
return false
14+
}
15+
defer res.Body.Close()
16+
17+
return res.StatusCode == http.StatusOK
18+
}
19+
1020
func checkHttpHostLatency(host string) time.Duration {
1121
start := time.Now()
1222
_, err := http.Get(host)

0 commit comments

Comments
 (0)