aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-04-04 20:42:18 -0400
committerUnknwon <u@gogs.io>2017-04-04 20:42:18 -0400
commitc05717a5f086c172e67b0bb9cd351e0e972de93d (patch)
tree8ff189a105e3846e88454b24760605ee28d4832d
parent5a488b6517bd6a9980c3f226231ff21a4ca06746 (diff)
models/mirror: feed git.IsRepoURLAccessible with raw mirror address
-rw-r--r--models/mirror.go24
-rw-r--r--routers/api/v1/repo/repo.go2
-rw-r--r--routers/repo/http.go1
-rw-r--r--routers/repo/repo.go4
4 files changed, 18 insertions, 13 deletions
diff --git a/models/mirror.go b/models/mirror.go
index 754ee25f..30a0155f 100644
--- a/models/mirror.go
+++ b/models/mirror.go
@@ -121,13 +121,13 @@ func (m *Mirror) readAddress() {
log.Error(2, "Load: %v", err)
return
}
- m.address = unescapeMirrorCredentials(cfg.Section("remote \"origin\"").Key("url").Value())
+ m.address = cfg.Section("remote \"origin\"").Key("url").Value()
}
-// HandleCloneUserCredentials replaces user credentials from HTTP/HTTPS URL
+// HandleMirrorCredentials replaces user credentials from HTTP/HTTPS URL
// with placeholder <credentials>.
-// It will fail for any other forms of clone addresses.
-func HandleCloneUserCredentials(url string, mosaics bool) string {
+// It returns original string if protocol is not HTTP/HTTPS.
+func HandleMirrorCredentials(url string, mosaics bool) string {
i := strings.Index(url, "@")
if i == -1 {
return url
@@ -145,21 +145,27 @@ func HandleCloneUserCredentials(url string, mosaics bool) string {
// Address returns mirror address from Git repository config without credentials.
func (m *Mirror) Address() string {
m.readAddress()
- return HandleCloneUserCredentials(m.address, false)
+ return HandleMirrorCredentials(m.address, false)
}
// MosaicsAddress returns mirror address from Git repository config with credentials under mosaics.
func (m *Mirror) MosaicsAddress() string {
m.readAddress()
- return HandleCloneUserCredentials(m.address, true)
+ return HandleMirrorCredentials(m.address, true)
}
-// FullAddress returns mirror address from Git repository config.
-func (m *Mirror) FullAddress() string {
+// RawAddress returns raw mirror address directly from Git repository config.
+func (m *Mirror) RawAddress() string {
m.readAddress()
return m.address
}
+// FullAddress returns mirror address from Git repository config with unescaped credentials.
+func (m *Mirror) FullAddress() string {
+ m.readAddress()
+ return unescapeMirrorCredentials(m.address)
+}
+
// escapeCredentials returns mirror address with escaped credentials.
func escapeMirrorCredentials(addr string) string {
start, end, found := findPasswordInMirrorAddress(addr)
@@ -191,7 +197,7 @@ func (m *Mirror) runSync() bool {
// Do a fast-fail testing against on repository URL to ensure it is accessible under
// good condition to prevent long blocking on URL resolution without syncing anything.
if !git.IsRepoURLAccessible(git.NetworkOptions{
- URL: m.FullAddress(),
+ URL: m.RawAddress(),
Timeout: 10 * time.Second,
}) {
desc := fmt.Sprintf("Source URL of mirror repository '%s' is not accessible: %s", m.Repo.FullName(), m.MosaicsAddress())
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index d7109f78..e0f62baf 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -270,7 +270,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
- ctx.Error(500, "MigrateRepository", models.HandleCloneUserCredentials(err.Error(), true))
+ ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
return
}
diff --git a/routers/repo/http.go b/routers/repo/http.go
index 7c1f690e..b3b6aa1a 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -111,7 +111,6 @@ func HTTPContexter() macaron.Handler {
askCredentials(c, http.StatusUnauthorized, "")
return
}
- fmt.Println(authUsername, authPassword)
authUser, err := models.UserSignIn(authUsername, authPassword)
if err != nil && !errors.IsUserNotExist(err) {
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 3626ac49..a3e5291d 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -217,11 +217,11 @@ func MigratePost(ctx *context.Context, f form.MigrateRepo) {
if strings.Contains(err.Error(), "Authentication failed") ||
strings.Contains(err.Error(), "could not read Username") {
ctx.Data["Err_Auth"] = true
- ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &f)
+ ctx.RenderWithErr(ctx.Tr("form.auth_failed", models.HandleMirrorCredentials(err.Error(), true)), MIGRATE, &f)
return
} else if strings.Contains(err.Error(), "fatal:") {
ctx.Data["Err_CloneAddr"] = true
- ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleCloneUserCredentials(err.Error(), true)), MIGRATE, &f)
+ ctx.RenderWithErr(ctx.Tr("repo.migrate.failed", models.HandleMirrorCredentials(err.Error(), true)), MIGRATE, &f)
return
}