6
6
package admin
7
7
8
8
import (
9
+ "encoding/json"
9
10
"fmt"
10
11
"net/url"
11
12
"os"
@@ -25,6 +26,7 @@ import (
25
26
"code.gitea.io/gitea/services/mailer"
26
27
27
28
"gitea.com/macaron/macaron"
29
+ "gitea.com/macaron/session"
28
30
"github.com/unknwon/com"
29
31
)
30
32
@@ -207,7 +209,7 @@ func SendTestMail(ctx *context.Context) {
207
209
ctx .Redirect (setting .AppSubURL + "/admin/config" )
208
210
}
209
211
210
- func shadownPasswordKV (cfgItem , splitter string ) string {
212
+ func shadowPasswordKV (cfgItem , splitter string ) string {
211
213
fields := strings .Split (cfgItem , splitter )
212
214
for i := 0 ; i < len (fields ); i ++ {
213
215
if strings .HasPrefix (fields [i ], "password=" ) {
@@ -218,10 +220,10 @@ func shadownPasswordKV(cfgItem, splitter string) string {
218
220
return strings .Join (fields , splitter )
219
221
}
220
222
221
- func shadownURL (provider , cfgItem string ) string {
223
+ func shadowURL (provider , cfgItem string ) string {
222
224
u , err := url .Parse (cfgItem )
223
225
if err != nil {
224
- log .Error ("shodowPassword %v failed: %v" , provider , err )
226
+ log .Error ("Shadowing Password for %v failed: %v" , provider , err )
225
227
return cfgItem
226
228
}
227
229
if u .User != nil {
@@ -239,7 +241,7 @@ func shadownURL(provider, cfgItem string) string {
239
241
func shadowPassword (provider , cfgItem string ) string {
240
242
switch provider {
241
243
case "redis" :
242
- return shadownPasswordKV (cfgItem , "," )
244
+ return shadowPasswordKV (cfgItem , "," )
243
245
case "mysql" :
244
246
//root:@tcp(localhost:3306)/macaron?charset=utf8
245
247
atIdx := strings .Index (cfgItem , "@" )
@@ -253,15 +255,21 @@ func shadowPassword(provider, cfgItem string) string {
253
255
case "postgres" :
254
256
// user=jiahuachen dbname=macaron port=5432 sslmode=disable
255
257
if ! strings .HasPrefix (cfgItem , "postgres://" ) {
256
- return shadownPasswordKV (cfgItem , " " )
258
+ return shadowPasswordKV (cfgItem , " " )
257
259
}
258
-
260
+ fallthrough
261
+ case "couchbase" :
262
+ return shadowURL (provider , cfgItem )
259
263
// postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
260
- // Notice: use shadwonURL
264
+ // Notice: use shadowURL
265
+ case "VirtualSession" :
266
+ var realSession session.Options
267
+ if err := json .Unmarshal ([]byte (cfgItem ), & realSession ); err == nil {
268
+ return shadowPassword (realSession .Provider , realSession .ProviderConfig )
269
+ }
261
270
}
262
271
263
- // "couchbase"
264
- return shadownURL (provider , cfgItem )
272
+ return cfgItem
265
273
}
266
274
267
275
// Config show admin config page
0 commit comments