common-rod 1.6.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -129,12 +129,23 @@ function _init(callback, commonRodOpt={mongo_create_connect:true, detaillog_add_
129
129
 
130
130
  // Middleware parser
131
131
  let bodyParser = require('body-parser');
132
+ let collectRawData = function(req, res, buf, encoding) {
133
+ req.rodRawData = buf.toString(encoding);
134
+ };
135
+
132
136
  app.use(bodyParser.urlencoded({
137
+ verify: collectRawData,
133
138
  limit: envCommonRod.body_parser_limit,
134
139
  extended: true
135
140
  }));
136
- app.use(bodyParser.json({limit: envCommonRod.body_parser_limit}));
137
- app.use(bodyParser.text({type:"text/*", limit: envCommonRod.body_parser_limit}));
141
+ app.use(bodyParser.json({
142
+ verify: collectRawData,
143
+ limit: envCommonRod.body_parser_limit,
144
+ }));
145
+ app.use(bodyParser.text({
146
+ verify: collectRawData,
147
+ type:"text/*", limit: envCommonRod.body_parser_limit
148
+ }));
138
149
 
139
150
 
140
151
  //obtainSession + assign invoke
@@ -718,7 +729,8 @@ async function _connectMongodb(appRodSession, mongoConf){
718
729
  Object.assign( opt, {
719
730
  useNewUrlParser: true,
720
731
  useUnifiedTopology: true,
721
- poolSize: 10
732
+ poolSize: 10,
733
+ serverSelectionTimeoutMS:10000 //timeout for driver connect to mongo
722
734
  })
723
735
 
724
736
  if(mongoConf.replicaSet){
@@ -90,22 +90,22 @@ function genOptionAttribute(rodSession, optionAttribute) {
90
90
  }else{
91
91
  optionAttribute._invoke = optionAttribute.headers['X-Tid'];
92
92
  }
93
- optionAttribute._logHeaders = JSON.stringify(optionAttribute.headers); //to write log
93
+ // optionAttribute._logHeaders = JSON.stringify(optionAttribute.headers); //to write log //10/03/2022 stringify when use
94
94
 
95
95
  // optionAttribute.option = option;
96
96
  // optionAttribute.body = optionAttribute.body || optionAttribute.option.body //case method delete want to send body
97
97
 
98
98
  optionAttribute._reqTime = new Date();
99
99
  optionAttribute._maxRetry = conf.max_retry;
100
- if( rodSession.detail().isRawDataEnabled() ){
100
+ // if( rodSession.detail().isRawDataEnabled() ){
101
101
  optionAttribute._rawData = null;
102
102
  if( optionAttribute.data ){
103
103
  optionAttribute._rawData = typeof optionAttribute.data === 'string' ? optionAttribute.data : JSON.stringify(optionAttribute.data);
104
104
  }
105
105
 
106
- }else{
107
- optionAttribute._rawData = null;
108
- }
106
+ // }else{
107
+ // optionAttribute._rawData = null;
108
+ // }
109
109
  return optionAttribute;
110
110
  }
111
111
 
@@ -143,12 +143,12 @@ async function requestHttp(rodSession, optionAttributes, ins) {
143
143
 
144
144
 
145
145
  let processLog = maskCredential.outgoing_request_detail(optionAttribute._service+'.'+optionAttribute._command, {
146
- "Header" : optionAttribute.headers,
146
+ "Header" : {...optionAttribute.headers},
147
147
  "Url" : getURL(optionAttribute),
148
148
  "QueryString" : optionAttribute.params || null,
149
- "Body" : optionAttribute.data,
149
+ "Body" : optionAttribute.data, //NOT SHALLOW CLONE
150
150
  "_RawData": optionAttribute._rawData //REMOVE AFTER CALL outgoing_request_detail
151
- });
151
+ }, rodSession.detail().isRawDataEnabled());
152
152
  let rawData = processLog._RawData;
153
153
  delete processLog._RawData;
154
154
 
@@ -225,7 +225,7 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
225
225
 
226
226
  let processLog = maskCredential.incoming_response_detail(optionAttribute._service+'.'+optionAttribute._command, {
227
227
  Body:data,
228
- Header:headers,
228
+ Header:{...headers},
229
229
  _RawData: rawData
230
230
  });
231
231
  rawData = processLog._RawData;
@@ -243,7 +243,7 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
243
243
 
244
244
  for (const input of rodSession.detail().Input) {
245
245
  let reqLog = maskCredential.outgoing_request(optionAttribute._service+'.'+optionAttribute._command, optionAttribute);
246
- let resLog = maskCredential.incoming_response(optionAttribute._service+'.'+optionAttribute._command, response, input, data);
246
+ let resLog = maskCredential.incoming_response(optionAttribute._service+'.'+optionAttribute._command, response, input, data, rawData);
247
247
  // let indexPrev = ins.prevOutput.findIndex(output => output.Invoke === input.Invoke);
248
248
  // if(indexPrev > -1 ){
249
249
  // let output = ins.prevOutput.splice(indexPrev,1)[0];
@@ -254,7 +254,7 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
254
254
  trancLog += ' __METHOD='.concat(optionAttribute.method);
255
255
  trancLog += ' __COMMAND='.concat(optionAttribute._command);
256
256
  trancLog += ' __URL='.concat(optionAttribute.url);
257
- trancLog += ' __REQHEADERS='.concat(optionAttribute._logHeaders);
257
+ trancLog += ' __REQHEADERS='.concat(JSON.stringify(optionAttribute.headers));
258
258
  trancLog += ' __REQBODY='.concat(optionAttribute._rawData);
259
259
  }else{
260
260
  trancLog += reqLog;
@@ -309,7 +309,12 @@ async function handleError(rodSession, error, ins, optionAttribute) {
309
309
 
310
310
  //response = 'TIMEOUT';
311
311
  response = ERROR_TBL.TIMEOUT;
312
- }else if(error.code === 'ENOTFOUND' || error.code === 'ECONNRESET' || error.code === 'ECONNREFUSED' || error.code === 'EAI_AGAIN' ){
312
+ }else if(error.code === 'ENOTFOUND' ||
313
+ error.code === 'ECONNRESET' ||
314
+ error.code === 'ECONNREFUSED' ||
315
+ error.code === 'EAI_AGAIN' ||
316
+ error.code === 'ENETUNREACH'){
317
+
313
318
  rodSession.debug('receive CONNECTION_ERROR from', optionAttribute.url);
314
319
  rodSession.summary().addErrorBlock(optionAttribute._service, optionAttribute._command, 'ret=1', 'connection error');
315
320
  rodSession.detail().addInputResponseError(optionAttribute._service, optionAttribute._command, optionAttribute._invoke);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  *
3
- *
3
+ * data_path_body //true == body typeof string
4
4
  * {
5
5
  //mask pattern
6
6
  "mask_template":{
@@ -103,6 +103,52 @@
103
103
  var _ = require('lodash');
104
104
  const utils = require('./utils');
105
105
 
106
+ function readWithPath(path, obj, cb, currentPath=0){
107
+ path = Array.isArray(path) ? path : path.split(".");
108
+
109
+ for (let i = currentPath; i < path.length; i++) {
110
+ const subPath = path[i];
111
+ if(subPath.endsWith('[]')){
112
+ let newSubPath = subPath.slice(0, -2); //cut []
113
+ if(Array.isArray(obj[newSubPath])){
114
+ for (let j = 0; j < obj[newSubPath].length; j++) {
115
+ if(i+1 < path.length){//
116
+ //send path with new array
117
+ readWithPath(path, obj[newSubPath][j], cb, i+1);
118
+ }else{
119
+ // console.log("+",path.join("."), obj[newSubPath][j]);
120
+ let newValue = cb(obj[newSubPath][j]);
121
+ if(newValue){
122
+ obj[newSubPath][j] = newValue;
123
+ }
124
+ }
125
+ }
126
+ obj = obj[newSubPath];
127
+ break;
128
+
129
+ }else if(obj[newSubPath] == undefined){
130
+ // console.log(path.join("."), null);
131
+ }else{
132
+ console.log("path " + path.join(".") + " is not array");
133
+ }
134
+ }else{
135
+ try {
136
+ if(i+1 < path.length){
137
+ obj = obj[subPath];
138
+ }else{
139
+ // console.log("+",path.join("."), obj[subPath]);
140
+ let newValue = cb(obj[subPath]);
141
+ if(newValue){
142
+ obj[subPath] = newValue;
143
+ }
144
+ }
145
+ } catch (error) {
146
+ }
147
+
148
+ }
149
+ }
150
+ }
151
+
106
152
  let maskCredential = function () {
107
153
  let mask_credentails;
108
154
 
@@ -140,9 +186,10 @@ let maskCredential = function () {
140
186
 
141
187
  let body;
142
188
  if (typeof req.body === 'object') {
143
- body = {
144
- ...req.body
145
- }
189
+ // body = {
190
+ // ...req.body
191
+ // }
192
+ body = JSON.parse(req.rodRawData);//DEEP COPY
146
193
  } else if (typeof req.body === 'string') {
147
194
  body = req.body;
148
195
  } else {
@@ -192,21 +239,21 @@ let maskCredential = function () {
192
239
  mask_credentails.mask_template[mask.type]) {
193
240
  for (let index = 0; index < mask.app_log.body.length; index++) {
194
241
  const bodyPath = mask.app_log.body[index];
195
- let bdpValue = _.get(body, bodyPath);
196
- if (bdpValue && typeof bdpValue === 'string') {
197
- let mt = mask_credentails.mask_template[mask.type];
198
- for (let k = 0; k < mt.length; k++) {
199
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
200
- if (replaced) {
201
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
202
- _.set(body, bodyPath, bdpValue);
203
- if (mt[k].continue !== true) {
204
- break;
242
+ readWithPath(bodyPath, body, (bdpValue)=>{
243
+ if (bdpValue && typeof bdpValue === 'string') {
244
+ let mt = mask_credentails.mask_template[mask.type];
245
+ for (let k = 0; k < mt.length; k++) {
246
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
247
+ if (replaced) {
248
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
249
+ if (mt[k].continue !== true) {
250
+ break;
251
+ }
205
252
  }
206
253
  }
254
+ return bdpValue;
207
255
  }
208
- }
209
-
256
+ });
210
257
  }
211
258
  }
212
259
  }
@@ -237,18 +284,19 @@ let maskCredential = function () {
237
284
  }
238
285
 
239
286
  let body;
240
- let rawData = null;
287
+ let rawData = req.rodRawData;
241
288
  if (typeof req.body === 'object') {
242
- rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
243
- body = {
244
- ...req.body
245
- }
289
+ // rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
290
+ // body = {
291
+ // ...req.body
292
+ // }
293
+ body = JSON.parse(rawData);//DEEP COPY
246
294
  } else if (typeof req.body === 'string') {
247
295
  body = req.body;
248
- rawData = req.body;
296
+ // rawData = req.body;
249
297
  } else {
250
298
  body = req.body;
251
- rawData = req.body;
299
+ // rawData = req.body;
252
300
  }
253
301
 
254
302
  for (let i = 0; i < mask_credentails.mask_data.incoming_request[cmd].mask.length; i++) {
@@ -309,21 +357,21 @@ let maskCredential = function () {
309
357
  mask_credentails.mask_template[mask.type]) {
310
358
  for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
311
359
  const bodyPath = mask.detail_log.data_path_body[index];
312
- let bdpValue = _.get(body, bodyPath);
313
- if (bdpValue && typeof bdpValue === 'string') {
314
- let mt = mask_credentails.mask_template[mask.type];
315
- for (let k = 0; k < mt.length; k++) {
316
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
317
- if (replaced) {
318
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
319
- _.set(body, bodyPath, bdpValue);
320
- if (mt[k].continue !== true) {
321
- break;
360
+ readWithPath(bodyPath, body, (bdpValue)=>{
361
+ if (bdpValue && typeof bdpValue === 'string') {
362
+ let mt = mask_credentails.mask_template[mask.type];
363
+ for (let k = 0; k < mt.length; k++) {
364
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
365
+ if (replaced) {
366
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
367
+ if (mt[k].continue !== true) {
368
+ break;
369
+ }
322
370
  }
323
371
  }
372
+ return bdpValue;
324
373
  }
325
- }
326
-
374
+ });
327
375
  }
328
376
  }
329
377
  }
@@ -343,7 +391,8 @@ let maskCredential = function () {
343
391
  } else {
344
392
  let rawData = null;
345
393
  if (detailLog.isRawDataEnabled()) {
346
- rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
394
+ // rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
395
+ rawData = req.rodRawData;
347
396
  }
348
397
  let inputCmd = detailLog.Scenario; //avoid case change cmd name
349
398
  detailLog.addInputRequest("client", inputCmd, req.invoke,
@@ -394,7 +443,7 @@ let maskCredential = function () {
394
443
  let copyHeaders = {
395
444
  ...res._headers
396
445
  }
397
- let body;
446
+ let body; //res.body is not effect with real resp
398
447
  if (typeof res.body === 'object') {
399
448
  body = {
400
449
  ...res.body
@@ -448,21 +497,21 @@ let maskCredential = function () {
448
497
  mask_credentails.mask_template[mask.type]) {
449
498
  for (let index = 0; index < mask.app_log.body.length; index++) {
450
499
  const bodyPath = mask.app_log.body[index];
451
- let bdpValue = _.get(body, bodyPath);
452
- if (bdpValue && typeof bdpValue === 'string') {
453
- let mt = mask_credentails.mask_template[mask.type];
454
- for (let k = 0; k < mt.length; k++) {
455
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
456
- if (replaced) {
457
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
458
- _.set(body, bodyPath, bdpValue);
459
- if (mt[k].continue !== true) {
460
- break;
500
+ readWithPath(bodyPath, body, (bdpValue)=>{
501
+ if (bdpValue && typeof bdpValue === 'string') {
502
+ let mt = mask_credentails.mask_template[mask.type];
503
+ for (let k = 0; k < mt.length; k++) {
504
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
505
+ if (replaced) {
506
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
507
+ if (mt[k].continue !== true) {
508
+ break;
509
+ }
461
510
  }
462
511
  }
512
+ return bdpValue;
463
513
  }
464
- }
465
-
514
+ });
466
515
  }
467
516
  }
468
517
  }
@@ -526,7 +575,7 @@ let maskCredential = function () {
526
575
  }
527
576
  }
528
577
  }
529
-
578
+ //header
530
579
  if (mask.detail_log.data_path_headers) {
531
580
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
532
581
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -545,9 +594,10 @@ let maskCredential = function () {
545
594
  }
546
595
  }
547
596
  }
548
- if (mask.app_log.body && body) {
549
- if (typeof mask.app_log.body === 'boolean' &&
550
- mask.app_log.body === true &&
597
+ //body
598
+ if (mask.detail_log.data_path_body && body) {
599
+ if (typeof mask.detail_log.data_path_body === 'boolean' &&
600
+ mask.detail_log.data_path_body === true &&
551
601
  typeof body === 'string' &&
552
602
  mask_credentails.mask_template[mask.type]) {
553
603
  let mt = mask_credentails.mask_template[mask.type];
@@ -561,26 +611,26 @@ let maskCredential = function () {
561
611
  }
562
612
  }
563
613
 
564
- } else if (Array.isArray(mask.app_log.body) &&
614
+ } else if (Array.isArray(mask.detail_log.data_path_body) &&
565
615
  typeof body === 'object' &&
566
616
  mask_credentails.mask_template[mask.type]) {
567
- for (let index = 0; index < mask.app_log.body.length; index++) {
568
- const bodyPath = mask.app_log.body[index];
569
- let bdpValue = _.get(body, bodyPath);
570
- if (bdpValue && typeof bdpValue === 'string') {
571
- let mt = mask_credentails.mask_template[mask.type];
572
- for (let k = 0; k < mt.length; k++) {
573
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
574
- if (replaced) {
575
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
576
- _.set(body, bodyPath, bdpValue);
577
- if (mt[k].continue !== true) {
578
- break;
617
+ for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
618
+ const bodyPath = mask.detail_log.data_path_body[index];
619
+ readWithPath(bodyPath, body, (bdpValue)=>{
620
+ if (bdpValue && typeof bdpValue === 'string') {
621
+ let mt = mask_credentails.mask_template[mask.type];
622
+ for (let k = 0; k < mt.length; k++) {
623
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
624
+ if (replaced) {
625
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
626
+ if (mt[k].continue !== true) {
627
+ break;
628
+ }
579
629
  }
580
630
  }
631
+ return bdpValue;
581
632
  }
582
- }
583
-
633
+ });
584
634
  }
585
635
  }
586
636
  }
@@ -646,11 +696,13 @@ let maskCredential = function () {
646
696
  }
647
697
 
648
698
 
649
- let body;
699
+ let body;
650
700
  if (typeof optionAttribute.data === 'object') {
651
- body = {
652
- ...optionAttribute.data
653
- }
701
+ // body = {
702
+ // ...optionAttribute.data
703
+ // }
704
+ body = JSON.parse(optionAttribute._rawData);//DEEP COPY
705
+
654
706
  } else if (typeof optionAttribute.data === 'string') {
655
707
  body = optionAttribute.data;
656
708
  } else {
@@ -699,20 +751,21 @@ let maskCredential = function () {
699
751
  mask_credentails.mask_template[mask.type]) {
700
752
  for (let index = 0; index < mask.app_log.body.length; index++) {
701
753
  const bodyPath = mask.app_log.body[index];
702
- let bdpValue = _.get(body, bodyPath);
703
- if (bdpValue && typeof bdpValue === 'string') {
704
- let mt = mask_credentails.mask_template[mask.type];
705
- for (let k = 0; k < mt.length; k++) {
706
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
707
- if (replaced) {
708
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
709
- _.set(body, bodyPath, bdpValue);
710
- if (mt[k].continue !== true) {
711
- break;
754
+ readWithPath(bodyPath, body, (bdpValue)=>{
755
+ if (bdpValue && typeof bdpValue === 'string') {
756
+ let mt = mask_credentails.mask_template[mask.type];
757
+ for (let k = 0; k < mt.length; k++) {
758
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
759
+ if (replaced) {
760
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
761
+ if (mt[k].continue !== true) {
762
+ break;
763
+ }
712
764
  }
713
765
  }
766
+ return bdpValue;
714
767
  }
715
- }
768
+ });
716
769
  }
717
770
  }
718
771
  }
@@ -732,7 +785,7 @@ let maskCredential = function () {
732
785
  }
733
786
  }
734
787
 
735
- let outgoing_request_detail = function (cmd, obj) {
788
+ let outgoing_request_detail = function (cmd, obj, enableRaw) {
736
789
  if (mask_credentails &&
737
790
  mask_credentails.mask_data &&
738
791
  mask_credentails.mask_data.outgoing_request &&
@@ -743,7 +796,7 @@ let maskCredential = function () {
743
796
  let mask = mask_credentails.mask_data.outgoing_request[cmd].mask[i];
744
797
  if (mask.detail_log) {
745
798
  //rawData
746
- if (mask.detail_log.raw_data && obj._RawData) {
799
+ if (mask.detail_log.raw_data && obj._RawData && enableRaw) {
747
800
  if (mask_credentails.mask_template[mask.type]) {
748
801
  let mt = mask_credentails.mask_template[mask.type];
749
802
  for (let k = 0; k < mt.length; k++) {
@@ -757,7 +810,7 @@ let maskCredential = function () {
757
810
  }
758
811
  }
759
812
  }
760
-
813
+ //header
761
814
  if (mask.detail_log.data_path_headers) {
762
815
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
763
816
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -776,8 +829,14 @@ let maskCredential = function () {
776
829
  }
777
830
  }
778
831
  }
779
-
832
+ //body
780
833
  if (mask.detail_log.data_path_body && obj.Body) {
834
+ if(obj._RawData){
835
+ obj.Body = JSON.parse(obj._RawData);//DEEP COPY
836
+ }else{
837
+ obj.Body = JSON.parse(JSON.stringify(obj.Body));
838
+ }
839
+
781
840
  if (typeof mask.detail_log.data_path_body === 'boolean' &&
782
841
  mask.detail_log.data_path_body === true &&
783
842
  typeof obj.Body === 'string' &&
@@ -798,20 +857,21 @@ let maskCredential = function () {
798
857
  mask_credentails.mask_template[mask.type]) {
799
858
  for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
800
859
  const bodyPath = mask.detail_log.data_path_body[index];
801
- let bdpValue = _.get(obj.Body, bodyPath);
802
- if (bdpValue && typeof bdpValue === 'string') {
803
- let mt = mask_credentails.mask_template[mask.type];
804
- for (let k = 0; k < mt.length; k++) {
805
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
806
- if (replaced) {
807
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
808
- _.set(obj.Body, bodyPath, bdpValue);
809
- if (mt[k].continue !== true) {
810
- break;
860
+ readWithPath(bodyPath, obj.Body, (bdpValue)=>{
861
+ if (bdpValue && typeof bdpValue === 'string') {
862
+ let mt = mask_credentails.mask_template[mask.type];
863
+ for (let k = 0; k < mt.length; k++) {
864
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
865
+ if (replaced) {
866
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
867
+ if (mt[k].continue !== true) {
868
+ break;
869
+ }
811
870
  }
812
871
  }
872
+ return bdpValue;
813
873
  }
814
- }
874
+ });
815
875
  }
816
876
  }
817
877
  }
@@ -825,19 +885,27 @@ let maskCredential = function () {
825
885
  }
826
886
 
827
887
 
828
- let incoming_response = function (cmd, response, input, data) {
888
+ let incoming_response = function (cmd, response, input, data, rawData) {
829
889
  if (mask_credentails &&
830
890
  mask_credentails.mask_data &&
831
891
  mask_credentails.mask_data.incoming_response &&
832
892
  mask_credentails.mask_data.incoming_response[cmd] &&
833
893
  mask_credentails.mask_data.incoming_response[cmd].mask) {
834
894
 
835
- let copyHeaders = response.headers;
836
- let body = data;
895
+ let copyHeaders = {...response.headers};
896
+ let body;
897
+ if (typeof data === 'object') {
898
+ body = JSON.parse(rawData);//DEEP COPY
899
+ } else if (typeof data === 'string') {
900
+ body = rawData;
901
+ } else {
902
+ body = rawData;
903
+ }
837
904
 
838
905
  for (let i = 0; i < mask_credentails.mask_data.incoming_response[cmd].mask.length; i++) {
839
906
  let mask = mask_credentails.mask_data.incoming_response[cmd].mask[i];
840
907
  if (mask.app_log) {
908
+ //header
841
909
  if (mask.app_log.headers) {
842
910
  for (let j = 0; j < mask.app_log.headers.length; j++) {
843
911
  let headerPath = mask.app_log.headers[j];
@@ -856,6 +924,7 @@ let maskCredential = function () {
856
924
  }
857
925
  }
858
926
  }
927
+ //body
859
928
  if (mask.app_log.body && body) {
860
929
  if (typeof mask.app_log.body === 'boolean' &&
861
930
  mask.app_log.body === true &&
@@ -877,21 +946,21 @@ let maskCredential = function () {
877
946
  mask_credentails.mask_template[mask.type]) {
878
947
  for (let index = 0; index < mask.app_log.body.length; index++) {
879
948
  const bodyPath = mask.app_log.body[index];
880
- let bdpValue = _.get(body, bodyPath);
881
- if (bdpValue && typeof bdpValue === 'string') {
882
- let mt = mask_credentails.mask_template[mask.type];
883
- for (let k = 0; k < mt.length; k++) {
884
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
885
- if (replaced) {
886
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
887
- _.set(body, bodyPath, bdpValue);
888
- if (mt[k].continue !== true) {
889
- break;
949
+ readWithPath(bodyPath, body, (bdpValue)=>{
950
+ if (bdpValue && typeof bdpValue === 'string') {
951
+ let mt = mask_credentails.mask_template[mask.type];
952
+ for (let k = 0; k < mt.length; k++) {
953
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
954
+ if (replaced) {
955
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
956
+ if (mt[k].continue !== true) {
957
+ break;
958
+ }
890
959
  }
891
960
  }
961
+ return bdpValue;
892
962
  }
893
- }
894
-
963
+ });
895
964
  }
896
965
  }
897
966
  }
@@ -912,12 +981,19 @@ let maskCredential = function () {
912
981
  }
913
982
 
914
983
  let incoming_response_detail = function (cmd, obj) {
915
-
984
+
916
985
  if (mask_credentails &&
917
986
  mask_credentails.mask_data &&
918
987
  mask_credentails.mask_data.incoming_response &&
919
988
  mask_credentails.mask_data.incoming_response[cmd] &&
920
989
  mask_credentails.mask_data.incoming_response[cmd].mask) {
990
+ if (typeof obj.Body === 'object') {
991
+ obj.Body = JSON.parse(obj._RawData);//DEEP COPY
992
+ } else if (typeof obj.Body === 'string') {
993
+ obj.Body = obj._RawData;
994
+ } else {
995
+ obj.Body = obj._RawData;
996
+ }
921
997
 
922
998
  for (let i = 0; i < mask_credentails.mask_data.incoming_response[cmd].mask.length; i++) {
923
999
  let mask = mask_credentails.mask_data.incoming_response[cmd].mask[i];
@@ -937,7 +1013,7 @@ let maskCredential = function () {
937
1013
  }
938
1014
  }
939
1015
  }
940
-
1016
+ //header
941
1017
  if (mask.detail_log.data_path_headers) {
942
1018
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
943
1019
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -956,6 +1032,7 @@ let maskCredential = function () {
956
1032
  }
957
1033
  }
958
1034
  }
1035
+ //body
959
1036
  if (mask.detail_log.data_path_body && obj.Body) {
960
1037
  if (typeof mask.detail_log.data_path_body === 'boolean' &&
961
1038
  mask.detail_log.data_path_body === true &&
@@ -977,21 +1054,21 @@ let maskCredential = function () {
977
1054
  mask_credentails.mask_template[mask.type]) {
978
1055
  for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
979
1056
  const bodyPath = mask.detail_log.data_path_body[index];
980
- let bdpValue = _.get(obj.Body, bodyPath);
981
- if (bdpValue && typeof bdpValue === 'string') {
982
- let mt = mask_credentails.mask_template[mask.type];
983
- for (let k = 0; k < mt.length; k++) {
984
- let replaced = bdpValue.search(mt[k].pattern) >= 0;
985
- if (replaced) {
986
- bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
987
- _.set(obj.Body, bodyPath, bdpValue);
988
- if (mt[k].continue !== true) {
989
- break;
1057
+ readWithPath(bodyPath, obj.Body, (bdpValue)=>{
1058
+ if (bdpValue && typeof bdpValue === 'string') {
1059
+ let mt = mask_credentails.mask_template[mask.type];
1060
+ for (let k = 0; k < mt.length; k++) {
1061
+ let replaced = bdpValue.search(mt[k].pattern) >= 0;
1062
+ if (replaced) {
1063
+ bdpValue = bdpValue.replace(mt[k].pattern, mt[k].mask_value);
1064
+ if (mt[k].continue !== true) {
1065
+ break;
1066
+ }
990
1067
  }
991
1068
  }
1069
+ return bdpValue;
992
1070
  }
993
- }
994
-
1071
+ });
995
1072
  }
996
1073
  }
997
1074
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "common-rod",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -299,4 +299,33 @@ let db = this.utils().mongo().getDb();
299
299
  change validator for mongo connection
300
300
  allow config ip,port OR host[].ip, host[].port
301
301
  ```
302
- ### Fixed
302
+ ### Fixed
303
+
304
+ # [1.6.1] - 2021-02-14
305
+ ### Added
306
+ ### Changed
307
+ ### Fixed
308
+ ```
309
+ add error code 'ENETUNREACH' to http request error
310
+ ```
311
+
312
+ # [1.7.0] - 2022-03-02
313
+ ### Added
314
+ ```
315
+ support config hideCredenmtial with object OR array
316
+ Example
317
+ foo.bar
318
+ foo.bar[]
319
+ foo[].bar[]
320
+ foo[0].bar[0]
321
+ ```
322
+ ### Changed
323
+ ### Fixed
324
+
325
+ # [1.7.1] - 2022-03-11
326
+ ### Added
327
+ ### Changed
328
+ ### Fixed
329
+ ```
330
+ Fix bug hideCredenmtial with nested object
331
+ ```