-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetElasticDataAndCreateAmmo.ts
executable file
·55 lines (53 loc) · 1.67 KB
/
getElasticDataAndCreateAmmo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import * as fs from 'fs';
import * as program from 'commander';
import { createAmmo } from './lib/AmmoGenerator/ammo';
import ammoConfJsonShema from './lib/GetDataOfElastic/GetElasticDataShema';
import GetDataOfElastic from './lib/GetDataOfElastic';
program
.option('-u,--user-agent <agent>', 'UserAgent')
.option('-c,--config <config>', 'Config file')
.option('-o <out>', 'Out filename')
.parse(process.argv);
(async () => {
try {
if (program.config) {
const file = JSON.parse(
fs.readFileSync(program.config as string, {
encoding: 'utf8',
}),
);
const validateRes = ammoConfJsonShema.validate(file);
if (validateRes.error) {
console.error(validateRes.error);
process.exit(1);
}
const res = await GetDataOfElastic(file);
let agent: string = 'Yandex-Tank';
if (program.userAgent) {
agent = program.userAgent;
}
let tmp = '';
for (const item of res.data) {
tmp += createAmmo(
item.method.toUpperCase().trim(),
file.host,
item.path,
item.tag,
agent,
JSON.stringify(item.body),
item.headers || {},
);
}
console.log(`Результаты сохранены в ${program.O || res.name}`);
console.log(`Колличество запросов === ${res.data.length}`);
fs.writeFileSync(`${process.env.PWD || './'}/${program.O || res.name}.txt`, tmp);
process.exit(0);
}
program.help();
console.log('example => tank-gen-ammo -c ./config.json -o qq -u YandexTankDev\n');
} catch (e) {
console.error(e);
process.exit(1);
}
})();