visualvault-api 1.2.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +23 -140
- package/dist/VVRestApi.cjs +2552 -0
- package/dist/VVRestApi.cjs.map +1 -0
- package/dist/VVRestApi.d.cts +386 -0
- package/dist/VVRestApi.d.ts +386 -0
- package/dist/VVRestApi.js +2522 -0
- package/dist/VVRestApi.js.map +1 -0
- package/{lib/VVRestApi/VVRestApiNodeJs → dist}/config.yml +3 -3
- package/dist/constants.cjs +45 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +48 -0
- package/dist/constants.d.ts +48 -0
- package/dist/constants.js +20 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.cjs +2572 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2541 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -70
- package/lib/VVRestApi/VVRestApiNodeJs/DocApi.js +0 -66
- package/lib/VVRestApi/VVRestApiNodeJs/FormsApi.js +0 -51
- package/lib/VVRestApi/VVRestApiNodeJs/NotificationsApi.js +0 -39
- package/lib/VVRestApi/VVRestApiNodeJs/ObjectsApi.js +0 -138
- package/lib/VVRestApi/VVRestApiNodeJs/StudioApi.js +0 -156
- package/lib/VVRestApi/VVRestApiNodeJs/VVRestApi.js +0 -1974
- package/lib/VVRestApi/VVRestApiNodeJs/app.js +0 -128
- package/lib/VVRestApi/VVRestApiNodeJs/common.js +0 -1598
- package/lib/VVRestApi/VVRestApiNodeJs/dts/express.d.ts +0 -125
- package/lib/VVRestApi/VVRestApiNodeJs/dts/node.d.ts +0 -1090
- package/lib/VVRestApi/VVRestApiNodeJs/files/237de37cf014ee1199a400d49e26e066.js +0 -51
- package/lib/VVRestApi/VVRestApiNodeJs/files/437833dc404aed118b0e644bf02b9c8a.js +0 -1
- package/lib/VVRestApi/VVRestApiNodeJs/log.js +0 -20
- package/lib/VVRestApi/VVRestApiNodeJs/public/favicon.ico +0 -0
- package/lib/VVRestApi/VVRestApiNodeJs/routes/scheduledscripts.js +0 -203
- package/lib/VVRestApi/VVRestApiNodeJs/routes/scripts.js +0 -215
- package/lib/VVRestApi/VVRestApiNodeJs/routes/testScheduledScripts.js +0 -131
- package/lib/VVRestApi/VVRestApiNodeJs/samples/SampleScheduledScript.js +0 -90
- package/lib/VVRestApi/VVRestApiNodeJs/samples/SendEmailScript.js +0 -51
- package/lib/VVRestApi/VVRestApiNodeJs/samples/fileTest.js +0 -60
- package/lib/VVRestApi/VVRestApiNodeJs/samples/sampleFormValidationScript.js +0 -126
- package/lib/VVRestApi/VVRestApiNodeJs/views/error.ejs +0 -8
- package/lib/VVRestApi/VVRestApiNodeJs/views/index.ejs +0 -8
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var vvEntities = require("../VVRestApi");
|
|
2
|
-
var logger = require('../log');
|
|
3
|
-
|
|
4
|
-
module.exports.getCredentials = function () {
|
|
5
|
-
var options = {};
|
|
6
|
-
options.baseUrl = "http://localhost/VisualVault4_1_13";
|
|
7
|
-
options.customerAlias = "Cust"; //Change this to your customer name
|
|
8
|
-
options.databaseAlias = "Default"; //Make sure this is the right database
|
|
9
|
-
options.userId = "860028f6-0fbf-4a13-99fd-598dcaad6a36"; //Vaultaccess user with HTTP API Access Key/Secret generated in user properties.
|
|
10
|
-
options.password = "c5MCZasWnIeEerz6SnXQw5WGE1r3JIxN7LhR66E0APU=";
|
|
11
|
-
options.clientId = "860028f6-0fbf-4a13-99fd-598dcaad6a36";
|
|
12
|
-
options.clientSecret = "c5MCZasWnIeEerz6SnXQw5WGE1r3JIxN7LhR66E0APU=";
|
|
13
|
-
options.audience = "e98f5a306fed4a279a2837dee47751b6";
|
|
14
|
-
return options;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
module.exports.main = function (vvClient, response, token) {
|
|
19
|
-
/*Script Name: NodeJSTestCommunicationScheduledProcess
|
|
20
|
-
Customer: Test
|
|
21
|
-
Purpose: Test to make sure communications between VV and NodeJS are working for new installations. Need to replace the credentials aboe with valid information. Setup as outside process, then as scheduled process. Run as scheduled process.
|
|
22
|
-
Date of Dev: 12/24/2014
|
|
23
|
-
Last Rev Date:
|
|
24
|
-
Revision Notes:
|
|
25
|
-
12/24/2014 - Jason: First Setup of the script
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
var scheduledProcessGUID = token;
|
|
29
|
-
|
|
30
|
-
vvClient.documents.getDocuments().then(function(result){
|
|
31
|
-
var documents = JSON.parse(result);
|
|
32
|
-
console.log(documents);
|
|
33
|
-
for(var doc in documents.data){
|
|
34
|
-
console.log(documents.data[doc]);
|
|
35
|
-
vvClient.files.getFileBytesId(documents.data[doc]['documentId']).then(function(result2){
|
|
36
|
-
var templates = JSON.parse(result2);
|
|
37
|
-
console.log(templates)
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
response.json(200, 'COMMUNICATION ARRIVED SUCCESSFULLY. THIS IS A CUSTOM MESSAGE COMING BACK FROM THE NODEJS SERVER.');
|
|
45
|
-
|
|
46
|
-
logger.info('COMMUNICATION ARRIVED SUCCESSFULLY TO THE NODEJS SERVER.');
|
|
47
|
-
|
|
48
|
-
vvClient.scheduledProcess.postCompletion(scheduledProcessGUID, 'complete', true, "Scheduled Process End has completed.");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var winston = require('winston');
|
|
2
|
-
|
|
3
|
-
var os = require("os");
|
|
4
|
-
var infoLogStreamName = 'nodejs-' + os.hostname().toLowerCase() + '-info';
|
|
5
|
-
var errorLogStreamName = 'nodejs-' + os.hostname().toLowerCase() + '-error';
|
|
6
|
-
|
|
7
|
-
const tsFormat = () => (new Date()).toUTCString();
|
|
8
|
-
|
|
9
|
-
var logger = new (winston.Logger)({
|
|
10
|
-
transports: [
|
|
11
|
-
new (winston.transports.Console)({ timestamp: tsFormat }),
|
|
12
|
-
new (winston.transports.File)({ timestamp: tsFormat, filename: infoLogStreamName + '.log' })
|
|
13
|
-
]
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
module.exports = logger;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
Binary file
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
var clientLibrary = require('../VVRestApi');
|
|
2
|
-
var logger = require('../log');
|
|
3
|
-
|
|
4
|
-
var VVScriptFilePath = require('path').dirname(require.main.filename) + '/files/';
|
|
5
|
-
var VVScriptFileRequirePath = require('path').dirname(require.main.filename) + '/files/';
|
|
6
|
-
|
|
7
|
-
exports.processRequest = function (req, res) {
|
|
8
|
-
logger.info('Call from VisualVault to scheduledscripts');
|
|
9
|
-
|
|
10
|
-
var fs = require('fs');
|
|
11
|
-
var Q = require('q');
|
|
12
|
-
var meta = { code: 200, error: '' };
|
|
13
|
-
var attemptCount = 0;
|
|
14
|
-
|
|
15
|
-
var script = null;
|
|
16
|
-
var scriptName = null;
|
|
17
|
-
var baseUrl = null;
|
|
18
|
-
var token = null;
|
|
19
|
-
|
|
20
|
-
if (req.body instanceof Array) {
|
|
21
|
-
for (var x = 0; x < req.body.length; x++) {
|
|
22
|
-
var key = req.body[x].Key;
|
|
23
|
-
var value = req.body[x].Value;
|
|
24
|
-
|
|
25
|
-
if (key == "script") {
|
|
26
|
-
//retrieve script from form encoded post
|
|
27
|
-
script = value;
|
|
28
|
-
} else if (key == "baseUrl") {
|
|
29
|
-
//retrieve baseUrl from form encoded post
|
|
30
|
-
baseUrl = value;
|
|
31
|
-
} else if (key == "token") {
|
|
32
|
-
//retrieve token from form encoded post
|
|
33
|
-
token = value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} else if (typeof (req.body.script) != 'undefined' && typeof (req.body.baseUrl) != 'undefined') {
|
|
37
|
-
//retrieve script from form encoded post
|
|
38
|
-
script = req.body.script;
|
|
39
|
-
|
|
40
|
-
//retrieve baseUrl from form encoded post
|
|
41
|
-
baseUrl = req.body.baseUrl;
|
|
42
|
-
|
|
43
|
-
//retrieve token from form encoded post
|
|
44
|
-
token = req.body.token;
|
|
45
|
-
} else if (typeof (req.query.name) != 'undefined') {
|
|
46
|
-
//retrieve script name from query string
|
|
47
|
-
scriptName = req.query.name;
|
|
48
|
-
|
|
49
|
-
if (typeof (req.query.baseUrl) != 'undefined') {
|
|
50
|
-
//retrieve baseUrl from query string
|
|
51
|
-
baseUrl = req.query.baseUrl;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//retrieve token from form encoded post
|
|
55
|
-
//token = req.query.token;
|
|
56
|
-
} else {
|
|
57
|
-
console.log('Error, body of request did not contain key/value pairs for script and baseurl');
|
|
58
|
-
logger.error("Error, body of request did not contain key/value pairs for baseurl. http 400 response returned.");
|
|
59
|
-
meta.code = 400;
|
|
60
|
-
meta.error = "Error, body of request did not contain key/value pairs for script and baseurl";
|
|
61
|
-
res.json(200, meta);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (script === null && scriptName === null) {
|
|
65
|
-
console.log('Error, body of request did not contain key/value pairs for script');
|
|
66
|
-
logger.error("Error, body of request did not contain key/value pairs for script. http 400 response returned.");
|
|
67
|
-
|
|
68
|
-
meta.code = 400;
|
|
69
|
-
meta.error = "Error, body of request did not contain key/value pairs for script";
|
|
70
|
-
res.json(200, meta);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (baseUrl === null && scriptName === null) {
|
|
74
|
-
console.log('Error, body of request did not contain key/value pairs for baseurl');
|
|
75
|
-
logger.error("Error, body of request did not contain key/value pairs for baseurl. http 400 response returned.");
|
|
76
|
-
meta.code = 400;
|
|
77
|
-
meta.error = "Error, body of request did not contain key/value pairs for baseurl";
|
|
78
|
-
res.json(200, meta);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (typeof req.query.id === 'string') {
|
|
83
|
-
var fileId = req.query.id;
|
|
84
|
-
|
|
85
|
-
//todo: need config parameter for this path location
|
|
86
|
-
console.log('attempting to write script to ' + VVScriptFilePath + fileId + ".js");
|
|
87
|
-
|
|
88
|
-
//todo: need config parameter for this path location
|
|
89
|
-
fs.writeFile(VVScriptFilePath + fileId + ".js", script, function (err) {
|
|
90
|
-
if (err) {
|
|
91
|
-
|
|
92
|
-
logger.info("Error, unable to write script file: " + err);
|
|
93
|
-
|
|
94
|
-
console.log('Error, unable to write script file: ' + err);
|
|
95
|
-
|
|
96
|
-
meta.code = 500;
|
|
97
|
-
meta.error = "File System error, unable to write script file.";
|
|
98
|
-
logger.error("File System error, unable to write script file. http 500 response returned.");
|
|
99
|
-
res.json(200, meta);
|
|
100
|
-
} else {
|
|
101
|
-
console.log("loading scheduledScript script file");
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
for (var p in require.cache) {
|
|
105
|
-
if (p.indexOf(fileId) > -1) {
|
|
106
|
-
logger.info("deleting cached scheduledScript script file: " + p);
|
|
107
|
-
delete require.cache[p];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
} catch (ex) {
|
|
111
|
-
logger.error("error loading scheduledScript script file " + ex);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
logger.info("Loading scheduledScript script file");
|
|
115
|
-
|
|
116
|
-
//load the script file we just saved to the filesystem
|
|
117
|
-
var scheduledScript = require(VVScriptFileRequirePath + fileId);
|
|
118
|
-
|
|
119
|
-
// YOU CAN SWAP OUT YOUR SCRIPT HERE IF YOU WANT TO TEST
|
|
120
|
-
//var scheduledScript = require("../test.js");
|
|
121
|
-
|
|
122
|
-
//get the customer name and other credentials
|
|
123
|
-
var params = scheduledScript.getCredentials();
|
|
124
|
-
|
|
125
|
-
//add baseUrl to parameters for vvClient
|
|
126
|
-
if (!params.baseUrl) {
|
|
127
|
-
params.baseUrl = baseUrl;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
logger.info("calling vvAuthorize.getVaultApi");
|
|
131
|
-
|
|
132
|
-
var vvAuthorize = new clientLibrary.authorize();
|
|
133
|
-
|
|
134
|
-
//making call to vvClient to get access token
|
|
135
|
-
Q
|
|
136
|
-
.when(
|
|
137
|
-
vvAuthorize.getVaultApi(params.clientId, params.clientSecret, params.userId, params.password, params.audience, params.baseUrl, params.customerAlias, params.databaseAlias)
|
|
138
|
-
)
|
|
139
|
-
.then(function (result) {
|
|
140
|
-
logger.info("Calling the scheduledScript's Main method");
|
|
141
|
-
|
|
142
|
-
scheduledScript.main(result, res, token);
|
|
143
|
-
})
|
|
144
|
-
.fail(function (error) {
|
|
145
|
-
logger.error("Error response from vvAuthorize.getVaultApi. http 401 response returned. " + error.message);
|
|
146
|
-
|
|
147
|
-
meta.code = 401;
|
|
148
|
-
meta.error = "Unable to acquire access token";
|
|
149
|
-
res.json(200, meta);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
} else if (typeof scriptName === 'string') {
|
|
154
|
-
try {
|
|
155
|
-
|
|
156
|
-
logger.info("Loading scheduled script file requested by query string: " + scriptName + ".js");
|
|
157
|
-
|
|
158
|
-
//load the requested script file
|
|
159
|
-
var scheduledScript = require("../../../../scripts/server-scripts/scheduled/" + scriptName + ".js");
|
|
160
|
-
|
|
161
|
-
//get the customer name and other credentials
|
|
162
|
-
var params = scheduledScript.getCredentials();
|
|
163
|
-
|
|
164
|
-
//add baseUrl to parameters for vvClient
|
|
165
|
-
if (!params.baseUrl) {
|
|
166
|
-
params.baseUrl = baseUrl;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var vvAuthorize = new clientLibrary.authorize();
|
|
170
|
-
|
|
171
|
-
//making call to vvClient to get access token
|
|
172
|
-
Q
|
|
173
|
-
.when(
|
|
174
|
-
vvAuthorize.getVaultApi(params.clientId, params.clientSecret, params.userId, params.password, params.audience, params.baseUrl, params.customerAlias, params.databaseAlias)
|
|
175
|
-
)
|
|
176
|
-
.then(function (result) {
|
|
177
|
-
logger.info("Calling the scheduledScript's Main method");
|
|
178
|
-
|
|
179
|
-
scheduledScript.main(result, res, token);
|
|
180
|
-
})
|
|
181
|
-
.fail(function (error) {
|
|
182
|
-
logger.error("Error response from vvAuthorize.getVaultApi. http 401 response returned. " + error.message);
|
|
183
|
-
|
|
184
|
-
meta.code = 401;
|
|
185
|
-
meta.error = "Unable to acquire access token";
|
|
186
|
-
res.json(200, meta);
|
|
187
|
-
});
|
|
188
|
-
} catch (ex) {
|
|
189
|
-
logger.error("http 500: Error Loading scheduled script file requested by query string: " + scriptName + ".js. http 500 response returned. " + ex);
|
|
190
|
-
|
|
191
|
-
meta.code = 500;
|
|
192
|
-
meta.error = "Unable to Load scheduled script file requested by query string: " + scriptName + ".js";
|
|
193
|
-
res.json(500, meta);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
} else {
|
|
197
|
-
meta.code = 400;
|
|
198
|
-
meta.error = "Script file Id not specified";
|
|
199
|
-
res.json(200, meta);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
var clientLibrary = require('../VVRestApi');
|
|
2
|
-
var logger = require('../log');
|
|
3
|
-
|
|
4
|
-
var VVScriptFilePath = require('path').dirname(require.main.filename) + '/files/';
|
|
5
|
-
var VVScriptFileRequirePath = require('path').dirname(require.main.filename) + '/files/';
|
|
6
|
-
|
|
7
|
-
exports.testsite = function (req, res) {
|
|
8
|
-
res.end('Hello. VisualVault Node.Js execution environment. Node Version ' + process.version);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.scripts = function (req, res) {
|
|
14
|
-
console.log('Call from VisualVault to scripts');
|
|
15
|
-
var fs = require('fs');
|
|
16
|
-
var Q = require('q');
|
|
17
|
-
var meta = { code: 200, error: '' };
|
|
18
|
-
|
|
19
|
-
var script = null;
|
|
20
|
-
var baseUrl = null;
|
|
21
|
-
var ffColl = null;
|
|
22
|
-
|
|
23
|
-
if (req.body instanceof Array) {
|
|
24
|
-
for (var x = 0; x < req.body.length; x++) {
|
|
25
|
-
var key = req.body[x].Key;
|
|
26
|
-
var value = req.body[x].Value;
|
|
27
|
-
|
|
28
|
-
if (key == "script") {
|
|
29
|
-
//retrieve script from form encoded post
|
|
30
|
-
script = value;
|
|
31
|
-
} else if (key == "baseUrl") {
|
|
32
|
-
//retrieve baseUrl from form encoded post
|
|
33
|
-
baseUrl = value;
|
|
34
|
-
} else if (key == "fields") {
|
|
35
|
-
//create formfield collection from form encoded post
|
|
36
|
-
if (value && value instanceof Array) {
|
|
37
|
-
ffColl = value;
|
|
38
|
-
} else if (value) {
|
|
39
|
-
ffColl = JSON.parse(value);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} else if (typeof (req.body.script) != 'undefined' && typeof (req.body.baseUrl) != 'undefined') {
|
|
44
|
-
//retrieve script from form encoded post
|
|
45
|
-
script = req.body.script;
|
|
46
|
-
|
|
47
|
-
//retrieve baseUrl from form encoded post
|
|
48
|
-
baseUrl = req.body.baseUrl;
|
|
49
|
-
|
|
50
|
-
if (typeof (req.body.fields) != 'undefined') {
|
|
51
|
-
//create formfield collection from form encoded post
|
|
52
|
-
ffColl = JSON.parse(req.body.fields);
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
logger.info('Error, body of request did not contain key/value pairs for script and baseurl');
|
|
56
|
-
meta.code = 400;
|
|
57
|
-
meta.error = "Error, body of request did not contain key/value pairs for script and baseurl";
|
|
58
|
-
res.json(200, meta);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (script === null) {
|
|
63
|
-
logger.info('Error, body of request did not contain key/value pairs for script');
|
|
64
|
-
meta.code = 400;
|
|
65
|
-
meta.error = "Error, body of request did not contain key/value pairs for script";
|
|
66
|
-
res.json(200, meta);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (baseUrl === null) {
|
|
70
|
-
logger.info('Error, body of request did not contain key/value pairs for baseurl');
|
|
71
|
-
meta.code = 400;
|
|
72
|
-
meta.error = "Error, body of request did not contain key/value pairs for baseurl";
|
|
73
|
-
res.json(200, meta);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//instantiate the formfieldcollection
|
|
77
|
-
var ffCollection = new clientLibrary.forms.formFieldCollection(ffColl);
|
|
78
|
-
|
|
79
|
-
if (typeof req.query.id === 'string') {
|
|
80
|
-
//set filename to id of script
|
|
81
|
-
var fileId = req.query.id;
|
|
82
|
-
var scriptToExecute = "";
|
|
83
|
-
|
|
84
|
-
if (fileId == "localScript") {
|
|
85
|
-
|
|
86
|
-
var scriptFilePath = '../../../../outsideScripts/' + script + ".js";
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
require.resolve(scriptFilePath);
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
scriptFilePath = VVScriptFilePath + script + ".js";
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
scriptToExecute = require(scriptFilePath);
|
|
96
|
-
|
|
97
|
-
//get the customer name and other credentials
|
|
98
|
-
var params = scriptToExecute.getCredentials();
|
|
99
|
-
|
|
100
|
-
//add baseUrl to parameters for vvClient
|
|
101
|
-
params.baseUrl = baseUrl;
|
|
102
|
-
|
|
103
|
-
//instantiate the authentication object
|
|
104
|
-
var vvAuthorize = new clientLibrary.authorize();
|
|
105
|
-
|
|
106
|
-
//call VisualVault to get access token
|
|
107
|
-
Q
|
|
108
|
-
.when(
|
|
109
|
-
vvAuthorize.getVaultApi(params.clientId, params.clientSecret, params.userId, params.password, params.audience, params.baseUrl, params.customerAlias, params.databaseAlias)
|
|
110
|
-
)
|
|
111
|
-
.then(function (result) {
|
|
112
|
-
logger.info("Calling the scriptToExecute's Main method");
|
|
113
|
-
|
|
114
|
-
scriptToExecute.main(ffCollection, result, res);
|
|
115
|
-
})
|
|
116
|
-
.fail(function (error) {
|
|
117
|
-
if (error.message && (error.message.indexOf('Authorization') >= 0 || error.message.indexOf('token') >= 0)) {
|
|
118
|
-
//error while acquiring access token
|
|
119
|
-
meta.code = 401;
|
|
120
|
-
meta.error = "Unable to acquire access token";
|
|
121
|
-
logger.info("Error response from acquire access token");
|
|
122
|
-
} else {
|
|
123
|
-
//error while executing script
|
|
124
|
-
meta.code = 500;
|
|
125
|
-
meta.error = error;
|
|
126
|
-
logger.info(error);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
res.json(200, meta);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
} else {
|
|
133
|
-
|
|
134
|
-
logger.info('attempting to write script to ' + VVScriptFilePath + fileId + ".js");
|
|
135
|
-
|
|
136
|
-
//write script out to filesystem
|
|
137
|
-
fs.writeFile(VVScriptFilePath + fileId + ".js", script, function (err) {
|
|
138
|
-
if (err) {
|
|
139
|
-
logger.info('Error, unable to write script file: ' + err);
|
|
140
|
-
|
|
141
|
-
meta.code = 500;
|
|
142
|
-
meta.error = "File System error, unable to write script file.";
|
|
143
|
-
res.json(200, meta);
|
|
144
|
-
|
|
145
|
-
logger.error(params.baseUrl + " Unable to write script file. http 500 response returned. " + error.message);
|
|
146
|
-
} else {
|
|
147
|
-
logger.info("loading scriptToExecute script file");
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
for (var p in require.cache) {
|
|
151
|
-
if (p.indexOf(fileId) > -1) {
|
|
152
|
-
console.log("deleting cached scriptToExecute script file: " + p);
|
|
153
|
-
delete require.cache[p];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
} catch (ex) {
|
|
157
|
-
console.log(ex);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// YOU CAN SWAP OUT YOUR SCRIPT HERE IF YOU WANT TO TEST
|
|
161
|
-
scriptToExecute = require(VVScriptFileRequirePath + fileId);
|
|
162
|
-
//scriptToExecute = require(VVScriptFileRequirePath);
|
|
163
|
-
|
|
164
|
-
//get the customer name and other credentials
|
|
165
|
-
var params = scriptToExecute.getCredentials();
|
|
166
|
-
|
|
167
|
-
//add baseUrl to parameters for vvClient unless script explicity requested an override
|
|
168
|
-
if (!params.baseUrlOverride) {
|
|
169
|
-
params.baseUrl = baseUrl;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//instantiate the authentication object
|
|
173
|
-
var vvAuthorize = new clientLibrary.authorize();
|
|
174
|
-
|
|
175
|
-
//call VisualVault to get access token
|
|
176
|
-
Q
|
|
177
|
-
.when(
|
|
178
|
-
vvAuthorize.getVaultApi(params.clientId, params.clientSecret, params.userId, params.password, params.audience, params.baseUrl, params.customerAlias, params.databaseAlias)
|
|
179
|
-
)
|
|
180
|
-
.then(function (result) {
|
|
181
|
-
logger.info(params.baseUrl + " calling script " + scriptToExecute + " Main method");
|
|
182
|
-
|
|
183
|
-
//result is the clientLibrary object returned after authentication
|
|
184
|
-
scriptToExecute.main(ffCollection, result, res);
|
|
185
|
-
})
|
|
186
|
-
.fail(function (error) {
|
|
187
|
-
if (error.message && (error.message.indexOf('Authorization') >= 0 || error.message.indexOf('token') >= 0)) {
|
|
188
|
-
//error while acquiring access token
|
|
189
|
-
meta.code = 401;
|
|
190
|
-
meta.error = "Unable to acquire access token";
|
|
191
|
-
logger.error(params.baseUrl + " Error acquiring access token. http 401 response returned. " + error.message);
|
|
192
|
-
} else {
|
|
193
|
-
//error while executing script
|
|
194
|
-
meta.code = 500;
|
|
195
|
-
meta.error = error;
|
|
196
|
-
logger.error(params.baseUrl + " Error acquiring access token. http 500 response returned. " + error.message);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
res.json(200, meta);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
meta.code = 400;
|
|
207
|
-
meta.error = "Script file Id not specified";
|
|
208
|
-
logger.error(params.baseUrl + " Script file Id not specified. http 400 response returned. " + error.message);
|
|
209
|
-
res.json(200, meta);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
var clientLibrary = require('../VVRestApi');
|
|
2
|
-
var logger = require('../log');
|
|
3
|
-
|
|
4
|
-
var VVScriptFilePath = require('path').dirname(require.main.filename) + '/files/';
|
|
5
|
-
var VVScriptFileRequirePath = require('path').dirname(require.main.filename) + '/files/';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.processRequest = function (req, res) {
|
|
9
|
-
logger.info('Request received for test script');
|
|
10
|
-
|
|
11
|
-
var fs = require('fs');
|
|
12
|
-
var Q = require('q');
|
|
13
|
-
var meta = { code: 200, error: '' };
|
|
14
|
-
var attemptCount = 0;
|
|
15
|
-
|
|
16
|
-
var script = null;
|
|
17
|
-
var scriptName = null;
|
|
18
|
-
var baseUrl = null;
|
|
19
|
-
var token = null;
|
|
20
|
-
|
|
21
|
-
if (req.body instanceof Array) {
|
|
22
|
-
for (var x = 0; x < req.body.length; x++) {
|
|
23
|
-
var key = req.body[x].Key;
|
|
24
|
-
var value = req.body[x].Value;
|
|
25
|
-
|
|
26
|
-
if (key == "script") {
|
|
27
|
-
//retrieve script from form encoded post
|
|
28
|
-
script = value;
|
|
29
|
-
} else if (key == "baseUrl") {
|
|
30
|
-
//retrieve baseUrl from form encoded post
|
|
31
|
-
baseUrl = value;
|
|
32
|
-
} else if (key == "token") {
|
|
33
|
-
//retrieve token from form encoded post
|
|
34
|
-
token = value;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} else if (typeof (req.body.script) != 'undefined' && typeof (req.body.baseUrl) != 'undefined') {
|
|
38
|
-
//retrieve script from form encoded post
|
|
39
|
-
script = req.body.script;
|
|
40
|
-
|
|
41
|
-
//retrieve baseUrl from form encoded post
|
|
42
|
-
baseUrl = req.body.baseUrl;
|
|
43
|
-
|
|
44
|
-
//retrieve token from form encoded post
|
|
45
|
-
token = req.body.token;
|
|
46
|
-
} else if (typeof (req.params.name) != 'undefined') {
|
|
47
|
-
//retrieve script name from query string
|
|
48
|
-
scriptName = req.params.name;
|
|
49
|
-
|
|
50
|
-
if (typeof (req.query.baseUrl) != 'undefined') {
|
|
51
|
-
//retrieve baseUrl from query string
|
|
52
|
-
baseUrl = req.query.baseUrl;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
} else {
|
|
56
|
-
console.log('Error, body of request did not contain key/value pairs for script and baseurl');
|
|
57
|
-
logger.error("Error, body of request did not contain key/value pairs for baseurl. http 400 response returned.");
|
|
58
|
-
meta.code = 400;
|
|
59
|
-
meta.error = "Error, body of request did not contain key/value pairs for script and baseurl";
|
|
60
|
-
res.json(200, meta);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (script === null && scriptName === null) {
|
|
64
|
-
console.log('Error, body of request did not contain key/value pairs for script');
|
|
65
|
-
logger.error("Error, body of request did not contain key/value pairs for script. http 400 response returned.");
|
|
66
|
-
|
|
67
|
-
meta.code = 400;
|
|
68
|
-
meta.error = "Error, body of request did not contain key/value pairs for script";
|
|
69
|
-
res.json(200, meta);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (baseUrl === null && scriptName === null) {
|
|
73
|
-
console.log('Error, body of request did not contain key/value pairs for baseurl');
|
|
74
|
-
logger.error("Error, body of request did not contain key/value pairs for baseurl. http 400 response returned.");
|
|
75
|
-
meta.code = 400;
|
|
76
|
-
meta.error = "Error, body of request did not contain key/value pairs for baseurl";
|
|
77
|
-
res.json(200, meta);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (typeof scriptName === 'string') {
|
|
82
|
-
try {
|
|
83
|
-
|
|
84
|
-
logger.info("Loading test script file: " + scriptName + ".js");
|
|
85
|
-
|
|
86
|
-
//load the requested script file
|
|
87
|
-
var testScript = require(process.cwd() + "/scripts/test-scripts/scheduled/" + scriptName + ".js");
|
|
88
|
-
|
|
89
|
-
//get the customer name and other credentials
|
|
90
|
-
var params = testScript.getCredentials();
|
|
91
|
-
|
|
92
|
-
//add baseUrl to parameters for vvClient
|
|
93
|
-
if (!params.baseUrl) {
|
|
94
|
-
params.baseUrl = baseUrl;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var vvAuthorize = new clientLibrary.authorize();
|
|
98
|
-
|
|
99
|
-
//making call to vvClient to get access token
|
|
100
|
-
Q
|
|
101
|
-
.when(
|
|
102
|
-
vvAuthorize.getVaultApi(params.clientId, params.clientSecret, params.userId, params.password, params.audience, params.baseUrl, params.customerAlias, params.databaseAlias)
|
|
103
|
-
)
|
|
104
|
-
.then(function (result) {
|
|
105
|
-
logger.info("Calling the test script's Main method");
|
|
106
|
-
|
|
107
|
-
testScript.main(result, res, token);
|
|
108
|
-
})
|
|
109
|
-
.fail(function (error) {
|
|
110
|
-
logger.error("Error response from vvAuthorize.getVaultApi. http 401 response returned. " + error.message);
|
|
111
|
-
|
|
112
|
-
meta.code = 401;
|
|
113
|
-
meta.error = "Unable to acquire access token";
|
|
114
|
-
res.json(200, meta);
|
|
115
|
-
});
|
|
116
|
-
} catch (ex) {
|
|
117
|
-
logger.error("http 500: Error Loading scheduled script file: " + scriptName + ".js. http 500 response returned. " + ex);
|
|
118
|
-
|
|
119
|
-
meta.code = 500;
|
|
120
|
-
meta.error = "Unable to Load script file: " + scriptName + ".js";
|
|
121
|
-
res.json(500, meta);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
} else {
|
|
125
|
-
meta.code = 400;
|
|
126
|
-
meta.error = "Script name not specified";
|
|
127
|
-
res.json(200, meta);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
|