generated from ministryofjustice/cloud-platform-terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canary_node.tmpl
55 lines (44 loc) · 1.63 KB
/
canary_node.tmpl
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
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');
const apiCanaryBlueprint = async function () {
// Handle validation for positive scenario
const validateSuccessfull = async function(res) {
return new Promise((resolve, reject) => {
if (res.statusCode < 200 || res.statusCode > 299) {
throw res.statusCode + ' ' + res.statusMessage;
}
let responseBody = '';
res.on('data', (d) => {
responseBody += d;
});
res.on('end', () => {
// Add validation on 'responseBody' here if required.
resolve();
});
});
};
// Set request option for Verify ${endpointpath}
let requestOptionsStep1 = {
hostname: '${hostname}',
method: 'GET',
path: '${endpointpath}',
port: '${port}',
protocol: 'https:',
body: "",
headers: {}
};
requestOptionsStep1['headers']['User-Agent'] = [synthetics.getCanaryUserAgentString(), requestOptionsStep1['headers']['User-Agent']].join(' ');
// Set step config option for Verify ${endpointpath}
let stepConfig1 = {
includeRequestHeaders: false,
includeResponseHeaders: false,
includeRequestBody: false,
includeResponseBody: false,
restrictedHeaders: [],
continueOnHttpStepFailure: true
};
await synthetics.executeHttpStep('Verify ${endpointpath}', requestOptionsStep1, validateSuccessfull, stepConfig1);
};
exports.handler = async () => {
return await apiCanaryBlueprint();
};