-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
741 lines (630 loc) · 22.9 KB
/
index.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
var fs = require("fs");
var request = require('request');
var response = null
var userid = null
var password = null
var noproxy = false
var sslverify = true
var url = null
var cert = null
var timeout = 3600
var basicauth = null
var auth = null
var apipath = '/ae/api/v1'
async function connect(options, callback) {
if (typeof options === "function") {
callback = options;
options = null;
}
if (options.noproxy != null) noproxy = options.noproxy;
if (options.sslverify != null) sslverify = options.sslverify;
if (options.userid != null && options.userid.trim() != "") userid = options.userid;
if (options.password != null && options.password.trim() != "") password = options.password;
if (options.basicauth != null || options.basicauth.trim() != "") basicauth = options.basicauth;
if (options.url != null && options.url.trim() != "") url = options.url;
if (options.cert != null && options.cert.trim() != "") cert = options.cert;
if (options.timeout != null && options.timeout.toString().trim() != "") timeout = options.timeout;
if (callback == null) callback = defaultCallback;
//handleSSL()
handleProxy()
setAuth()
return this
}
exports.connect = connect
const setPath = (str, cl) => {
return str.replace("{client_id}", cl)
}
const setAuth = () => {
if (basicauth != null) {
auth = "Basic " + basicauth
} else {
auth = "Basic " + Buffer.from(userid + ":" + password).toString("base64");
}
}
const handleProxy = () => {
if (noproxy == true) {
const urlObject = new URL(url);
const domain = urlObject.hostname;
process.env['NO_PROXY'] = domain;
}
}
const handleSSL = () => {
if (sslverify == false) {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
process.emitWarning = (warning, options) => {
if (warning && warning.includes && warning.includes('NODE_TLS_REJECT_UNAUTHORIZED')) {
return
}
return originalEmitWarning.call(process, warning, options)
}
}
}
const getUrl = (path) => {
return url + apipath + path
}
function doRequest(opt) {
console.log(timeout)
if (opt.body == null) opt.body = {};
return new Promise(function(resolve, reject) {
try {
request({
url: getUrl(opt.path),
method: opt.method,
//requestCert: false,
headers: {
"Authorization": auth,
'Content-type': 'application/json',
'Accept': 'application/json'
},
//timeout: timeout,
body: JSON.stringify(opt.body)
},
function(error, response, body) {
if (opt.path == '/ping'){
var data = {}
}else{
var data = JSON.parse(body)
}
data.statusCode = response.statusCode
if (!error && response.statusCode == 200) {
data.statusTest = 'success'
resolve(data);
} else {
data.statusTest = 'error'
resolve(data);
}
}
)
} catch {
return {
"error": "url unreachable"
}
}
})
}
function defaultCallback(err) {
if (err) throw err;
}
async function activateScript(client_id, body=null){
// Summary: Runs scripts written in the Automation Engine scripting language.
var path = '/{client_id}/scripts'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.activateScript = activateScript
async function branchDiff(client_id, branch_name=null, query=null){
// Summary: Get content of two files to see their differences.
var path = '/{client_id}/repositories/branches/{branch_name}/diff'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{branch_name}', branch_name)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.branchDiff = branchDiff
async function branchLog(client_id, branch_name=null, query=null){
// Summary: Retrieves the history of the repository for max_results entries.
var path = '/{client_id}/repositories/branches/{branch_name}/log'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{branch_name}', branch_name)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.branchLog = branchLog
async function changeExecutionStatus(client_id, run_id, body=null){
// Summary: Changes the status of an execution.
var path = '/{client_id}/executions/{run_id}/status'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.changeExecutionStatus = changeExecutionStatus
async function commitChanges(client_id, body=null){
// Summary: Commits only changed objects for client to repository.
var path = '/{client_id}/repositories/commits'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.commitChanges = commitChanges
async function computeErtEstimations(client_id, run_id){
// Summary: Get ERT estimations for the given workflow.
var path = '/{client_id}/executions/{run_id}/ert'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.computeErtEstimations = computeErtEstimations
async function createBranch(client_id, body=null){
// Summary: Create a new branch.
var path = '/{client_id}/repositories/branches'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.createBranch = createBranch
async function createComments(client_id, run_id, body=null){
// Summary: Appends a comment to a given execution.
var path = '/{client_id}/executions/{run_id}/comments'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.createComments = createComments
async function createForecast(client_id, body=null){
// Summary: Create a forecast.
var path = '/{client_id}/forecasts'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.createForecast = createForecast
async function createRepository(client_id, body=null){
// Summary: Initializes the repository for the specified client.
var path = '/{client_id}/repositories'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.createRepository = createRepository
async function deleteClients(client_id, target_client_id=null, body=null){
// Summary: Delete a client
var path = '/{client_id}/system/clients/{client_id}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{target_client_id}', target_client_id)
return await doRequest({
path: path,
method: 'delete',
body: body
})
}
exports.deleteClients = deleteClients
async function deleteForecast(client_id, body=null){
// Summary: Delete forecasts using ids.
var path = '/{client_id}/forecasts'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'delete',
body: body
})
}
exports.deleteForecast = deleteForecast
async function deleteRepository(client_id, body=null){
// Summary: Abort merging so we get out of merging state.
var path = '/{client_id}/repositories/merge'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'delete'
})
}
exports.deleteRepository = deleteRepository
async function executeObject(client_id, body=null){
// Summary: Execute an object with or without input parameters (promptsets variables).
var path = '/{client_id}/executions'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.executeObject = executeObject
async function exportTelemetry(client_id, start_from=null){
// Summary: Retrieve telemetry data per month as json for the last n months, including the current month. Only works for client 0.
var path = '/{client_id}/telemetry/export/{start_from}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{start_from}', start_from)
return await doRequest({
path: path,
method: 'get'
})
}
exports.exportTelemetry = exportTelemetry
async function findObjects(client_id, body=null){
// Summary: Search the process assembly for objects using different filter criteria.
var path = '/{client_id}/search'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.findObjects = findObjects
async function getAgentDetails(client_id, object_name=null){
// Summary: Returns detailed agent information
var path = '/{client_id}/system/agents/{object_name}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
return await doRequest({
path: path,
method: 'get'
})
}
exports.getAgentDetails = getAgentDetails
async function getChanges(client_id, query=null){
// Summary: Returns a list of objects that have uncommitted changes.
var path = '/{client_id}/repositories/changes'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.getChanges = getChanges
async function getChildrenOfExecution(client_id, run_id, query=null){
// Summary: Gets all immediate execution children, ordered descending by activation_time and run_id.
var path = '/{client_id}/executions/{run_id}/children'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.getChildrenOfExecution = getChildrenOfExecution
async function getExecution(client_id, run_id, query=null){
// Summary: Get details of a given execution.
var path = '/{client_id}/executions/{run_id}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.getExecution = getExecution
async function getFeatureList(client_id){
// Summary: Retrieve system feature information.
var path = '/{client_id}/system/features'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.getFeatureList = getFeatureList
async function getForecast(client_id, forecast_id=null, query=null){
// Summary: Get details of a given forecast.
var path = '/{client_id}/forecasts/{forecast_id}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{forecast_id}', forecast_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.getForecast = getForecast
async function getObjects(client_id, object_name=null, query=null){
// Summary: Can be used to export single objects by name
var path = '/{client_id}/objects/{object_name}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.getObjects = getObjects
async function getRepository(client_id){
// Summary: Retrieves repository information for the given client.
var path = '/{client_id}/repositories'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.getRepository = getRepository
async function getTimezoneInfo(client_id, object_name=null){
// Summary: Returns the time zone used by an object definition or defaults if the object or time zone does not exist.
var path = '/{client_id}/objects/{object_name}/timezone'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
return await doRequest({
path: path,
method: 'get'
})
}
exports.getTimezoneInfo = getTimezoneInfo
async function healthCheck(client_id){
// Summary: Can be used to determine if the automation system is in a healthy state. A system is healthy if there is a PWP and at least one instance of CP and JWP respectively. When healthy, HTTP 200 is returned. When unhealthy, HTTP 503. Note: only use the HTTP status code to determine the health status since the response body is optional.
var path = '/{client_id}/system/health'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.healthCheck = healthCheck
async function listAgentgroups(client_id){
// Summary:
var path = '/{client_id}/system/agentgroups'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listAgentgroups = listAgentgroups
async function listAgents(client_id, query=null){
// Summary: Lists all agents that are defined in the system. The returned list contains running and stopped agents.
var path = '/{client_id}/system/agents'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listAgents = listAgents
async function listBranches(client_id, query=null){
// Summary: Retrieves a list of branches.
var path = '/{client_id}/repositories/branches'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listBranches = listBranches
async function listClients(client_id){
// Summary: List of clients in the system.
var path = '/{client_id}/system/clients'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listClients = listClients
async function listComments(client_id, run_id){
// Summary: List all comments for a given execution.
var path = '/{client_id}/executions/{run_id}/comments'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listComments = listComments
async function listExecutions(client_id, query=null){
// Summary: List executions, ordered descending by activation_time and run_id.
var path = '/{client_id}/executions'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listExecutions = listExecutions
async function listForecastAgents(client_id, query=null){
// Summary: List forecast agents and gaps.
var path = '/{client_id}/forecasts/agents'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listForecastAgents = listForecastAgents
async function listForecasts(client_id, query=null){
// Summary: List all forecasts, ordered descending by start_time.
var path = '/{client_id}/forecasts'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listForecasts = listForecasts
async function listObjectInputs(client_id, object_name=null){
// Summary: List all inputs for a given object.
var path = '/{client_id}/objects/{object_name}/inputs'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listObjectInputs = listObjectInputs
async function listReportContent(client_id, run_id, report_type=null, query=null){
// Summary: Report content pages.
var path = '/{client_id}/executions/{run_id}/reports/{report_type}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
var path = path.replace('{report_type}', report_type)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'get'
})
}
exports.listReportContent = listReportContent
async function listReports(client_id, run_id){
// Summary: Report list for a given execution.
var path = '/{client_id}/executions/{run_id}/reports'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listReports = listReports
async function listVariables(client_id, run_id){
// Summary: List all variables for a given execution.
var path = '/{client_id}/executions/{run_id}/variables'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{run_id}', run_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.listVariables = listVariables
async function mergeBranchIntoActive(client_id, body=null){
// Summary: Merge another branch in active branch.
var path = '/{client_id}/repositories/merge'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.mergeBranchIntoActive = mergeBranchIntoActive
async function modifyForecast(client_id, forecast_id=null, body=null){
// Summary: Changes the title of a forecast item.
var path = '/{client_id}/forecasts/{forecast_id}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{forecast_id}', forecast_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.modifyForecast = modifyForecast
async function moveHead(client_id, commit_id=null, body=null){
// Summary: Imports version of provided GIT Hash to automation engine.
var path = '/{client_id}/repositories/commits/{commit_id}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{commit_id}', commit_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.moveHead = moveHead
async function ping(){
// Summary: Can be used to determine if the JCP process is currently running.
var path = '/ping'
return await doRequest({
path: path,
method: 'get'
})
}
exports.ping = ping
async function postObjects(client_id, body=null, query=null){
// Summary: Can be used to import single objects
var path = '/{client_id}/objects'
var path = path.replace('{client_id}', client_id)
if (query != null) path += '?'+query
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.postObjects = postObjects
async function productList(client_id){
// Summary: Retrieve available products
var path = '/{client_id}/telemetry/products'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'get'
})
}
exports.productList = productList
async function pullRepository(client_id, body=null){
// Summary: Pull changes from repository for active branch.
var path = '/{client_id}/repositories/pull'
var path = path.replace('{client_id}', client_id)
return await doRequest({
path: path,
method: 'post',
body: body
})
}
exports.pullRepository = pullRepository
async function usageForCalendarEvents(client_id, object_name=null, event_name=null){
// Summary: Returns a list of objects with a reference name, a boolean to show if the actual result has hidden objects due to acl conflicts, for the given objectname
var path = '/{client_id}/objects/{object_name}/usage/calendarevent/{event_name}'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
var path = path.replace('{event_name}', event_name)
return await doRequest({
path: path,
method: 'get'
})
}
exports.usageForCalendarEvents = usageForCalendarEvents
async function usageObject(client_id, object_name=null){
// Summary: Returns a list of objects with a reference name, a boolean to show if the actual result has hidden objects due to acl conflicts, for the given objectname
var path = '/{client_id}/objects/{object_name}/usage'
var path = path.replace('{client_id}', client_id)
var path = path.replace('{object_name}', object_name)
return await doRequest({
path: path,
method: 'get'
})
}
exports.usageObject = usageObject