-
Notifications
You must be signed in to change notification settings - Fork 3
Plugins
Iran Reyes Fleitas edited this page May 28, 2019
·
5 revisions
Adviser is modular and allows creating plugins, in this wiki page you will find everything you know about implementing a plugin.
Your plugin name must be named as adviser-plugin-[name]
, examples:
- adviser-plugin-audit-npm
- adviser-plugin-suspicious-packages
Adviser is expecting an object with all the defined rules, like:
{
"rules": {
"min-vulnerabilities-allowed": Rule,
"skip-vulnerabilities": Rule,
}
}
To define a rule, you should create a class the inherit from Adviser.Rule
; once you have the class you can use the rule lifecycle method to implement your rule.
- Constructor - Called when the rule is parsed by the engine
- run - Action rule method called when the engine runs the rule
- ruleExecutionFailed - Called when the rule execution failed
- ruleExecutionEnded - Called when the rule execution ended
class MinVulnerabilityAllowed extends Adviser.Rule {
constructor(context) {
console.log(context);
}
run(sandbox) {
return new Promise((resolve, reject) => {
setTimeout(() => {
sandbox.report({ message: 'lalalalalalal' });
resolve();
}, 3000);
});
}
ruleExecutionFailed(feedback, error) {
console.log(feedback);
}
ruleExecutionEnded(feedback) {
console.log(feedback);
}
}
MinVulnerabilityAllowed.meta = {
category: 'Vulnerabilities',
description: 'To be fill',
recommended: true,
docsUrl: 'https://github..com/jam3/',
schema: {
enum: ['low', 'moderate', 'high', 'critical']
}
};
Besides the unit tests for your Rule logic, if you would like to run your new rule with Adviser, follow the below steps:
- Run
$ npm link
where your plugin's package.json is - Create a new folder
- Create an empty package.json and install
adviser
($ npm install adviser
) - Run
$ npm link <your plugin name>
in your new folder - Create a config file
.adviserrc
(Read below for an example) - Run Adviser
{
"plugins": ["audit-npm"],
"rules": {
"audit-npm/min-vulnerabilities-allow": ["error", { "level": "high" }]
}
}