@@ -7,6 +7,7 @@ package models
7
7
8
8
import (
9
9
"fmt"
10
+ "net/url"
10
11
"strings"
11
12
"time"
12
13
@@ -119,7 +120,7 @@ func sanitizeOutput(output, repoPath string) (string, error) {
119
120
return util .SanitizeMessage (output , remoteAddr ), nil
120
121
}
121
122
122
- // Address returns mirror address from Git repository config without credentials.
123
+ // Address returns mirror address from Git repository config with credentials censored .
123
124
func (m * Mirror ) Address () string {
124
125
m .readAddress ()
125
126
return util .SanitizeURLCredentials (m .address , false )
@@ -131,6 +132,41 @@ func (m *Mirror) FullAddress() string {
131
132
return m .address
132
133
}
133
134
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
+
134
170
// SaveAddress writes new address to Git repository config.
135
171
func (m * Mirror ) SaveAddress (addr string ) error {
136
172
repoPath := m .Repo .RepoPath ()
0 commit comments