-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
71 lines (68 loc) · 2.05 KB
/
api.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const router = express.Router();
const { artilleryDelegate } = require("./artillery-delegate");
router.get('/', (req, res, next) => {
res.json({ message: "OK" });
});
router.put('/', (req, res, next) => {
res.json({ message: "OK" });
});
router.post('/', (req, res, next) => {
artilleryDelegate.deepPing(req, res)
.then((result) => {
res.json(result)
})
.catch((err) => {
res.status(400).json(err);
});
});
router.put('/download/:projectId/:scriptId', (req, res, next) => {
const projectId = req.params.projectId;
const scriptId = req.params.scriptId;
artilleryDelegate.downloadYaml(projectId, scriptId)
.then((result) => {
res.json(result)
})
.catch((err) => {
res.status(400).json(err);
});
});
router.post('/execute/:projectId/:scriptId', (req, res, next) => {
const yamlRequest = {
projectId: req.params.projectId, //sanitize this!!
scriptId: req.params.scriptId, //sanitize this!!
time: req.query.time,
target: req.query.target,
ipAddress: req.query.ipAddress
}
artilleryDelegate.executeYaml(yamlRequest)
.then((result) => {
res.json(result);
})
.catch((err) => {
res.status(400).json(err);
});
});
router.get('/output/:projectId', (req, res, next) => {
const projectId = req.params.projectId;
artilleryDelegate.listOutput(projectId)
.then((result) => {
res.json(result);
})
.catch((err) => {
res.status(400).json(err);
})
});
router.post('/output/:projectId/:scriptId', (req, res, next) => {
const projectId = req.params.projectId;
const scriptId = req.params.scriptId;
const time = req.query.time;
artilleryDelegate.uploadOutput(projectId, scriptId, time)
.then((result) => {
res.json(result);
})
.catch((err) => {
res.status(400).json(err);
});
});
module.exports = router;