16
16
17
17
var _ = require ( '@sailshq/lodash' ) ;
18
18
var async = require ( 'async' ) ;
19
+ var redactPasswords = require ( './private/redact-passwords' ) ;
19
20
var Helpers = require ( '../helpers' ) ;
20
21
21
22
module . exports = ( function sailsPostgresql ( ) {
@@ -62,7 +63,7 @@ module.exports = (function sailsPostgresql() {
62
63
} ) . execSync ( ) ;
63
64
} catch ( e ) {
64
65
setImmediate ( function done ( ) {
65
- return cb ( redactPasswordsInMeta ( e ) ) ;
66
+ return cb ( redactPasswords ( e ) ) ;
66
67
} ) ;
67
68
return ;
68
69
}
@@ -95,14 +96,14 @@ module.exports = (function sailsPostgresql() {
95
96
modelDefinitions : modelDefinitions
96
97
} ) . switch ( {
97
98
error : function error ( err ) {
98
- return next ( redactPasswordsInMeta ( err ) ) ;
99
+ return next ( redactPasswords ( err ) ) ;
99
100
} ,
100
101
success : function success ( ) {
101
102
return next ( ) ;
102
103
}
103
104
} ) ;
104
105
} , function asyncCb ( err ) {
105
- cb ( redactPasswordsInMeta ( err ) ) ;
106
+ cb ( redactPasswords ( err ) ) ;
106
107
} ) ;
107
108
} ,
108
109
@@ -130,12 +131,12 @@ module.exports = (function sailsPostgresql() {
130
131
query : query
131
132
} ) . switch ( {
132
133
error : function error ( err ) {
133
- return cb ( redactPasswordsInMeta ( err ) ) ;
134
+ return cb ( redactPasswords ( err ) ) ;
134
135
} ,
135
136
notUnique : function error ( errInfo ) {
136
137
var e = new Error ( errInfo . message ) ;
137
138
e . footprint = errInfo . footprint ;
138
- return cb ( redactPasswordsInMeta ( e ) ) ;
139
+ return cb ( redactPasswords ( e ) ) ;
139
140
} ,
140
141
success : function success ( report ) {
141
142
var record = report && report . record || undefined ;
@@ -158,12 +159,12 @@ module.exports = (function sailsPostgresql() {
158
159
query : query
159
160
} ) . switch ( {
160
161
error : function error ( err ) {
161
- return cb ( redactPasswordsInMeta ( err ) ) ;
162
+ return cb ( redactPasswords ( err ) ) ;
162
163
} ,
163
164
notUnique : function error ( errInfo ) {
164
165
var e = new Error ( errInfo . message ) ;
165
166
e . footprint = errInfo . footprint ;
166
- return cb ( redactPasswordsInMeta ( e ) ) ;
167
+ return cb ( redactPasswords ( e ) ) ;
167
168
} ,
168
169
success : function success ( report ) {
169
170
var records = report && report . records || undefined ;
@@ -186,7 +187,7 @@ module.exports = (function sailsPostgresql() {
186
187
query : query
187
188
} ) . switch ( {
188
189
error : function error ( err ) {
189
- return cb ( redactPasswordsInMeta ( err ) ) ;
190
+ return cb ( redactPasswords ( err ) ) ;
190
191
} ,
191
192
success : function success ( report ) {
192
193
return cb ( undefined , report . records ) ;
@@ -208,12 +209,12 @@ module.exports = (function sailsPostgresql() {
208
209
query : query
209
210
} ) . switch ( {
210
211
error : function error ( err ) {
211
- return cb ( redactPasswordsInMeta ( err ) ) ;
212
+ return cb ( redactPasswords ( err ) ) ;
212
213
} ,
213
214
notUnique : function error ( errInfo ) {
214
215
var e = new Error ( errInfo . message ) ;
215
216
e . footprint = errInfo . footprint ;
216
- return cb ( redactPasswordsInMeta ( e ) ) ;
217
+ return cb ( redactPasswords ( e ) ) ;
217
218
} ,
218
219
success : function success ( report ) {
219
220
if ( report ) {
@@ -239,7 +240,7 @@ module.exports = (function sailsPostgresql() {
239
240
query : query
240
241
} ) . switch ( {
241
242
error : function error ( err ) {
242
- return cb ( redactPasswordsInMeta ( err ) ) ;
243
+ return cb ( redactPasswords ( err ) ) ;
243
244
} ,
244
245
success : function success ( report ) {
245
246
if ( report ) {
@@ -265,7 +266,7 @@ module.exports = (function sailsPostgresql() {
265
266
query : query
266
267
} ) . switch ( {
267
268
error : function error ( err ) {
268
- return cb ( redactPasswordsInMeta ( err ) ) ;
269
+ return cb ( redactPasswords ( err ) ) ;
269
270
} ,
270
271
success : function success ( report ) {
271
272
return cb ( undefined , report ) ;
@@ -287,7 +288,7 @@ module.exports = (function sailsPostgresql() {
287
288
query : query
288
289
} ) . switch ( {
289
290
error : function error ( err ) {
290
- return cb ( redactPasswordsInMeta ( err ) ) ;
291
+ return cb ( redactPasswords ( err ) ) ;
291
292
} ,
292
293
success : function success ( report ) {
293
294
return cb ( undefined , report ) ;
@@ -309,7 +310,7 @@ module.exports = (function sailsPostgresql() {
309
310
query : query
310
311
} ) . switch ( {
311
312
error : function error ( err ) {
312
- return cb ( redactPasswordsInMeta ( err ) ) ;
313
+ return cb ( redactPasswords ( err ) ) ;
313
314
} ,
314
315
success : function success ( report ) {
315
316
return cb ( undefined , report ) ;
@@ -331,7 +332,7 @@ module.exports = (function sailsPostgresql() {
331
332
query : query
332
333
} ) . switch ( {
333
334
error : function error ( err ) {
334
- return cb ( redactPasswordsInMeta ( err ) ) ;
335
+ return cb ( redactPasswords ( err ) ) ;
335
336
} ,
336
337
success : function success ( report ) {
337
338
return cb ( undefined , report ) ;
@@ -364,7 +365,7 @@ module.exports = (function sailsPostgresql() {
364
365
meta : meta
365
366
} ) . switch ( {
366
367
error : function error ( err ) {
367
- return cb ( redactPasswordsInMeta ( err ) ) ;
368
+ return cb ( redactPasswords ( err ) ) ;
368
369
} ,
369
370
success : function success ( report ) {
370
371
// Waterline expects the result to be undefined if the table doesn't
@@ -393,7 +394,7 @@ module.exports = (function sailsPostgresql() {
393
394
meta : meta
394
395
} ) . switch ( {
395
396
error : function error ( err ) {
396
- return cb ( redactPasswordsInMeta ( err ) ) ;
397
+ return cb ( redactPasswords ( err ) ) ;
397
398
} ,
398
399
success : function success ( ) {
399
400
return cb ( ) ;
@@ -414,7 +415,7 @@ module.exports = (function sailsPostgresql() {
414
415
meta : meta
415
416
} ) . switch ( {
416
417
error : function error ( err ) {
417
- return cb ( redactPasswordsInMeta ( err ) ) ;
418
+ return cb ( redactPasswords ( err ) ) ;
418
419
} ,
419
420
success : function success ( ) {
420
421
return cb ( ) ;
@@ -435,10 +436,10 @@ module.exports = (function sailsPostgresql() {
435
436
meta : meta
436
437
} ) . switch ( {
437
438
error : function error ( err ) {
438
- return cb ( redactPasswordsInMeta ( err ) ) ;
439
+ return cb ( redactPasswords ( err ) ) ;
439
440
} ,
440
441
badConnection : function badConnection ( err ) {
441
- return cb ( redactPasswordsInMeta ( err ) ) ;
442
+ return cb ( redactPasswords ( err ) ) ;
442
443
} ,
443
444
success : function success ( ) {
444
445
return cb ( ) ;
@@ -460,7 +461,7 @@ module.exports = (function sailsPostgresql() {
460
461
meta : meta
461
462
} ) . switch ( {
462
463
error : function error ( err ) {
463
- return cb ( redactPasswordsInMeta ( err ) ) ;
464
+ return cb ( redactPasswords ( err ) ) ;
464
465
} ,
465
466
success : function success ( ) {
466
467
return cb ( ) ;
@@ -473,18 +474,4 @@ module.exports = (function sailsPostgresql() {
473
474
return adapter ;
474
475
} ) ( ) ;
475
476
476
- var REDACT_REPLACEMENT = '$1:****@' ;
477
- var REDACT_REGEX_SINGLE = / ^ ( p o s t g r e s : \/ \/ [ ^ : \s ] * ) : [ ^ @ \s ] * @ / ;
478
- var REDACT_REGEX_MULTI = / ( p o s t g r e s : \/ \/ [ ^ : \s ] * ) : [ ^ @ \s ] * @ / g;
479
-
480
- function redactPasswordsInMeta ( err ) {
481
- if ( err ) {
482
- if ( err . meta && err . meta . url ) {
483
- err . meta . url = err . meta . url . replace ( REDACT_REGEX_SINGLE , REDACT_REPLACEMENT ) ;
484
- }
485
- if ( err . message ) {
486
- err . message = err . message . replace ( REDACT_REGEX_MULTI , REDACT_REPLACEMENT ) ;
487
- }
488
- }
489
- return err ;
490
- }
477
+
0 commit comments