@@ -7,6 +7,7 @@ package models
77
88import (
99 "fmt"
10+ "net/url"
1011 "strings"
1112 "time"
1213
@@ -119,7 +120,7 @@ func sanitizeOutput(output, repoPath string) (string, error) {
119120 return util .SanitizeMessage (output , remoteAddr ), nil
120121}
121122
122- // Address returns mirror address from Git repository config without credentials.
123+ // Address returns mirror address from Git repository config with credentials censored .
123124func (m * Mirror ) Address () string {
124125 m .readAddress ()
125126 return util .SanitizeURLCredentials (m .address , false )
@@ -131,6 +132,41 @@ func (m *Mirror) FullAddress() string {
131132 return m .address
132133}
133134
135+ // AddressNoCredentials returns mirror address from Git repository config without credentials.
136+ func (m * Mirror ) AddressNoCredentials () string {
137+ m .readAddress ()
138+ u , err := url .Parse (m .address )
139+ if err != nil {
140+ // this shouldn't happen but just return it unsanitised
141+ return m .address
142+ }
143+ u .User = nil
144+ return u .String ()
145+ }
146+
147+ // Username returns the mirror address username
148+ func (m * Mirror ) Username () string {
149+ m .readAddress ()
150+ u , err := url .Parse (m .address )
151+ if err != nil {
152+ // this shouldn't happen but if it does return ""
153+ return ""
154+ }
155+ return u .User .Username ()
156+ }
157+
158+ // Password returns the mirror address password
159+ func (m * Mirror ) Password () string {
160+ m .readAddress ()
161+ u , err := url .Parse (m .address )
162+ if err != nil {
163+ // this shouldn't happen but if it does return ""
164+ return ""
165+ }
166+ password , _ := u .User .Password ()
167+ return password
168+ }
169+
134170// SaveAddress writes new address to Git repository config.
135171func (m * Mirror ) SaveAddress (addr string ) error {
136172 repoPath := m .Repo .RepoPath ()
0 commit comments