Skip to content

Commit 1ce2ce8

Browse files
author
Michael Hardeman
authored
Merge pull request #5 from MichaelAllenHardeman/develop
Develop
2 parents 8a132ef + 4c12ba4 commit 1ce2ce8

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

har-extractor/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
*.har
2-
*.har.extracted

har-extractor/har-extract.js

+35-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const fs = require ('fs');
22
const path = require ('path');
33

44
const DEFAULT_OPTIONS = {
5+
keepOptions: false,
6+
stripPrivateInfo: true,
57
input: 'dlive.tv.har',
68
url: 'https://graphigo.prd.dlive.tv/',
7-
output: 'dlive.tv.har.extracted',
8-
keepOptions: false
9+
output: 'extracted.dlive.tv.har'
910
};
1011

1112
function extractSelfDetails () {
@@ -23,7 +24,8 @@ function maybeExtractOptionalArguments (options) {
2324
let nextArg;
2425
while ((nextArg = process.argv.shift ())) {
2526
switch (nextArg) {
26-
case '-k': options.keepOptions = true; break;
27+
case '-k': options.keepOptions = true; break;
28+
case '-s': options.stripPrivateInfo = false; break;
2729
case '-i': required ('input', (options.input = process.argv.shift ())); break;
2830
case '-o': required ('output', (options.output = process.argv.shift ())); break;
2931
case '-u': required ('url', (options.url = process.argv.shift ())); break;
@@ -53,6 +55,8 @@ function processArguments() {
5355
`Usage: ${selfDetails.cmd} ${selfDetails.file} [options]\n\n` +
5456
' -k keep OPTIONS requests.\n' +
5557
` default: ${DEFAULT_OPTIONS.keepOptions}\n` +
58+
' -s strip private info (username, password, tokens).\n' +
59+
` default: ${DEFAULT_OPTIONS.stripPrivateInfo}\n` +
5660
' -i input the path to the .har you want to parse.\n' +
5761
` default: ${DEFAULT_OPTIONS.input}\n` +
5862
' -o output the path to what output file you want.\n' +
@@ -87,6 +91,31 @@ function writeOrCreateTextFile (fileName, data, callback) {
8791
});
8892
}
8993

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+
90119
//////////
91120
// Main //
92121
//////////
@@ -97,14 +126,11 @@ fs.readFile (options.input, 'utf8', (err, data) => {
97126
if (err) throw err;
98127

99128
let harObject = JSON.parse (data);
100-
let requests = harObject.log.entries;
101129

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);
106132

107-
writeOrCreateTextFile (options.output, json, (err) => {
133+
writeOrCreateTextFile (options.output, JSON.stringify(harObject, null, 2), (err) => {
108134
if (err) throw err;
109135

110136
console.log (options.output + ' written!');

0 commit comments

Comments
 (0)