@@ -2,10 +2,11 @@ const fs = require ('fs');
2
2
const path = require ( 'path' ) ;
3
3
4
4
const DEFAULT_OPTIONS = {
5
+ keepOptions : false ,
6
+ stripPrivateInfo : true ,
5
7
input : 'dlive.tv.har' ,
6
8
url : 'https://graphigo.prd.dlive.tv/' ,
7
- output : 'dlive.tv.har.extracted' ,
8
- keepOptions : false
9
+ output : 'extracted.dlive.tv.har'
9
10
} ;
10
11
11
12
function extractSelfDetails ( ) {
@@ -23,7 +24,8 @@ function maybeExtractOptionalArguments (options) {
23
24
let nextArg ;
24
25
while ( ( nextArg = process . argv . shift ( ) ) ) {
25
26
switch ( nextArg ) {
26
- case '-k' : options . keepOptions = true ; break ;
27
+ case '-k' : options . keepOptions = true ; break ;
28
+ case '-s' : options . stripPrivateInfo = false ; break ;
27
29
case '-i' : required ( 'input' , ( options . input = process . argv . shift ( ) ) ) ; break ;
28
30
case '-o' : required ( 'output' , ( options . output = process . argv . shift ( ) ) ) ; break ;
29
31
case '-u' : required ( 'url' , ( options . url = process . argv . shift ( ) ) ) ; break ;
@@ -53,6 +55,8 @@ function processArguments() {
53
55
`Usage: ${ selfDetails . cmd } ${ selfDetails . file } [options]\n\n` +
54
56
' -k keep OPTIONS requests.\n' +
55
57
` default: ${ DEFAULT_OPTIONS . keepOptions } \n` +
58
+ ' -s strip private info (username, password, tokens).\n' +
59
+ ` default: ${ DEFAULT_OPTIONS . stripPrivateInfo } \n` +
56
60
' -i input the path to the .har you want to parse.\n' +
57
61
` default: ${ DEFAULT_OPTIONS . input } \n` +
58
62
' -o output the path to what output file you want.\n' +
@@ -87,6 +91,31 @@ function writeOrCreateTextFile (fileName, data, callback) {
87
91
} ) ;
88
92
}
89
93
94
+ function shouldRemoveBecauseUrlIsWrong ( item , options ) {
95
+ return item . request . url !== options . url ;
96
+ }
97
+ function shouldRemoveBecauseIsOptions ( item , options ) {
98
+ return ( ! options . keepOptions && 'OPTIONS' === item . request . method ) ;
99
+ }
100
+
101
+ function filterOutIrrelevantLogEntries ( harObject , options ) {
102
+ harObject . log . entries = harObject . log . entries . filter ( ( item ) => {
103
+ return ! ( shouldRemoveBecauseUrlIsWrong ( item , options ) ||
104
+ shouldRemoveBecauseIsOptions ( item , options ) ) ;
105
+ } ) ;
106
+ }
107
+
108
+ function maybeStripPrivateInfoFromEntries ( harObject , options ) {
109
+ if ( ! options . stripPrivateInfo ) { return ; }
110
+ harObject . log . entries = harObject . log . entries . map ( ( item ) => {
111
+
112
+ // TODO: determine which requests contain PII
113
+ // TODO: replace that PII with something generic.
114
+
115
+ return item ;
116
+ } ) ;
117
+ }
118
+
90
119
//////////
91
120
// Main //
92
121
//////////
@@ -97,14 +126,11 @@ fs.readFile (options.input, 'utf8', (err, data) => {
97
126
if ( err ) throw err ;
98
127
99
128
let harObject = JSON . parse ( data ) ;
100
- let requests = harObject . log . entries ;
101
129
102
- let json = JSON . stringify ( requests . filter ( ( item ) => {
103
- return ( item . request . url === options . url
104
- && ( options . keepOptions || 'OPTIONS' !== item . request . method ) ) ;
105
- } ) , null , 2 ) ;
130
+ filterOutIrrelevantLogEntries ( harObject , options ) ;
131
+ maybeStripPrivateInfoFromEntries ( harObject , options ) ;
106
132
107
- writeOrCreateTextFile ( options . output , json , ( err ) => {
133
+ writeOrCreateTextFile ( options . output , JSON . stringify ( harObject , null , 2 ) , ( err ) => {
108
134
if ( err ) throw err ;
109
135
110
136
console . log ( options . output + ' written!' ) ;
0 commit comments