-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpluginRunner.js
92 lines (73 loc) · 3.28 KB
/
pluginRunner.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
const {exec} =require('child_process')
const { AzNodeRest } = require('./nodeSrc/east')
const wexc = require('util').promisify(exec)
var path = require('path')
const { erroResponseSchema } = require('./nodeSrc/functionResponseSchema')
const bfr = {maxBuffer: 1024 * 1024}
const {argv} = require('yargs')
const { checkSubProvider } = require('./nodeSrc/subProviderCheck')
// Control with NodeSchema
async function runner (script, NodeSchema, native) {
try {
if (native) {
let provider = native.split('providers')[1].split('/')[1]
let apiversion = checkSubProvider(native)
console.log(apiversion, 'API-version for', native)
// Check if there is explicit skip for sub-provider
try {
// console.log()
if ( require(`../providers/${provider}/.skip.json`).find(toSkip => native.match(toSkip))) {
console.log('subprovider skip for', native)
if (argv.addSkippedSubProviders) { return new erroResponseSchema(native,'skipped due to no checks available in subprovider')} else {
return;
}
}
} catch (error) {
// console.log('no subprovider skip')
}
//If provider is AAD there is no need to get ITEMID, proceed straight to functions and controls
if (require('../providers/ignore.json').includes(provider)) {
const schemaPayload ={
id:native.split('providers')[1].split('/')[2],
name:native.split('providers')[1].split('/')[2],
type:provider
}
return await new NodeSchema(schemaPayload)
} else {
var schemaPayload = await AzNodeRest(native,apiversion)
}
let result = await new NodeSchema(schemaPayload)
//console.log(result.controls)
return result
}
// Handle uncatched errors
} catch (error) {
return new erroResponseSchema(native,error)
}
if (NodeSchema && !script.match('mode=native') ) {
try {
var {stdout} = await wexc(script, bfr)
// Check if output is valid
schemaPayload = JSON.parse(stdout)
var result = await new NodeSchema(schemaPayload)
//console.log(result)
return result
}
catch(error) {
console.log(error)
return `Failed to process ${script}`
}
} else {
try {
var {stdout,stderr} = await wexc(script, bfr)
results = JSON.parse(stdout)
//console.log(results)
return results
}
catch(error) {
console.log(error)
return `Failed to process ${script}, due to ${JSON.stringify(error)}`
}
}
}
module.exports={runner,wexc}