-
Notifications
You must be signed in to change notification settings - Fork 4
/
getAccountSub.js
96 lines (85 loc) · 3 KB
/
getAccountSub.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var request = require('request-promise');
var querystring = require('querystring');
var async = require('async');
var util = require('util');
var settings = require('./settings.js');
function getAccountSubInfoList(commonPostData, accountList, accountSubInfoOutput, informCaller)
{
totalNumAccounts = accountList.length;
if(settings.printDebugInfo)
console.time("Get account info - total time");
async.forEachLimit(accountList, settings.numConcurrentConnections, function(account, cb){
getAccountSubInfo(commonPostData, account.accountId, accountSubInfoOutput, cb);
}, function(err){
if (err){
//deal with the error
console.log("error in checking sites")
informCaller();
}
if(settings.printDebugInfo)
console.timeEnd("Get account info - total time")
informCaller();
});
}
function getAccountSubInfo(commonPostData, accountId, accountSubInfoOutput, informCaller)
{
var postData = {};
postData.account_id = accountId;
// form data
postData = querystring.stringify(postData);
var options = {
method: 'POST',
port: 443,
uri: 'https://my.incapsula.com/api/prov/v1/accounts/subscription',
host: 'my.incapsula.com',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: postData,
path: '/api/prov/v1/accounts/subscription',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'x-API-Id': commonPostData.api_id, //Imperva Authorization
'x-API-Key': commonPostData.api_key, //Imperva Authorization
'Content-Length': postData.length
},
}
request(options)
.then(function (response) {
var isWebVolDDosPurchased = false;
var isAttackAnalyticsPurchased = false;
var jResponse = JSON.parse(response);
if (jResponse.res != 0)
{
console.log("Error retreiving information");
console.log(util.inspect(jResponse, {depth: null}));
return;
}
// Get Volumetric DDoS purchase status
for (var i = 0; i < jResponse.planStatus.additionalServices.planSectionRows.length; i++)
{
if (jResponse.planStatus.additionalServices.planSectionRows[i].name == "DDoS Protection")
{
if (jResponse.planStatus.additionalServices.planSectionRows[i].purchased != "None")
isWebVolDDosPurchased = true;
}
if (jResponse.planStatus.additionalServices.planSectionRows[i].name == "Web Attack Analytics")
{
if (jResponse.planStatus.additionalServices.planSectionRows[i].purchased != "0")
isAttackAnalyticsPurchased = true;
}
}
accountSubInfoOutput.push({"accountId": jResponse.planStatus.accountId, "accountName": jResponse.planStatus.accountName,
"isWebVolDDosPurchased": isWebVolDDosPurchased,
"isAttackAnalyticsPurchased": isAttackAnalyticsPurchased});
informCaller();
})
//Removed catch clause for better debug
// .catch(function (err) {
// Deal with the error
// console.log("error in getting account subscription info " + err);
// informCaller();
// })
}
module.exports.getAccountSubInfo = getAccountSubInfo;
module.exports.getAccountSubInfoList = getAccountSubInfoList;