aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_mirror.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-08-16 22:56:57 +0100
committerGitHub <noreply@github.com>2019-08-16 22:56:57 +0100
commitbee1227b2f64d33ecbb0c5972ffc1b7d9689f95f (patch)
tree557dd7a1e9bcac37b9c6e2e36ccc2a298076df1d /models/repo_mirror.go
parent867f46f78e5777d7bafe83cda3244c1001ce3e60 (diff)
downloadgitea-bee1227b2f64d33ecbb0c5972ffc1b7d9689f95f.tar.gz
gitea-bee1227b2f64d33ecbb0c5972ffc1b7d9689f95f.zip
Extract the username and password from the mirror url (#7651)
* Explode out mirror username and password * Update models/repo_mirror.go * Just roundtrip the password * remove unused declaration * Update templates/repo/settings/options.tmpl
Diffstat (limited to 'models/repo_mirror.go')
-rw-r--r--models/repo_mirror.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/models/repo_mirror.go b/models/repo_mirror.go
index 7f703a1c97..02c87daf69 100644
--- a/models/repo_mirror.go
+++ b/models/repo_mirror.go
@@ -7,6 +7,7 @@ package models
import (
"fmt"
+ "net/url"
"strings"
"time"
@@ -119,7 +120,7 @@ func sanitizeOutput(output, repoPath string) (string, error) {
return util.SanitizeMessage(output, remoteAddr), nil
}
-// Address returns mirror address from Git repository config without credentials.
+// Address returns mirror address from Git repository config with credentials censored.
func (m *Mirror) Address() string {
m.readAddress()
return util.SanitizeURLCredentials(m.address, false)
@@ -131,6 +132,41 @@ func (m *Mirror) FullAddress() string {
return m.address
}
+// AddressNoCredentials returns mirror address from Git repository config without credentials.
+func (m *Mirror) AddressNoCredentials() string {
+ m.readAddress()
+ u, err := url.Parse(m.address)
+ if err != nil {
+ // this shouldn't happen but just return it unsanitised
+ return m.address
+ }
+ u.User = nil
+ return u.String()
+}
+
+// Username returns the mirror address username
+func (m *Mirror) Username() string {
+ m.readAddress()
+ u, err := url.Parse(m.address)
+ if err != nil {
+ // this shouldn't happen but if it does return ""
+ return ""
+ }
+ return u.User.Username()
+}
+
+// Password returns the mirror address password
+func (m *Mirror) Password() string {
+ m.readAddress()
+ u, err := url.Parse(m.address)
+ if err != nil {
+ // this shouldn't happen but if it does return ""
+ return ""
+ }
+ password, _ := u.User.Password()
+ return password
+}
+
// SaveAddress writes new address to Git repository config.
func (m *Mirror) SaveAddress(addr string) error {
repoPath := m.Repo.RepoPath()