This commit is contained in:
Celogeek 2022-11-01 09:27:51 +01:00
parent 84422344a9
commit e359f7096f
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 84 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

64
index.js Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env node
async function readAudit() {
const chunks = []
const stdin = process.stdin
stdin.resume()
stdin.setEncoding('utf-8')
stdin.on('data', (chunk) => {
chunks.push(chunk)
})
return new Promise((resolve, reject) => {
stdin.on('end', () => {
resolve(JSON.parse(chunks.join('')))
});
stdin.on('error', () => {
reject(Error('error during read'))
})
stdin.on('timeout', () => {
reject(Error('timout during read'))
})
})
}
const severities = {
info: 'INFO',
low: 'MINOR',
moderate: 'MINOR',
high: 'CRITICAL',
critical: 'BLOCKER',
};
async function main() {
const pnpmAudit = await readAudit()
const issues = []
for (const advice of Object.values(pnpmAudit.advisories || [])) {
issues.push({
"engineId": "pnpm-audit",
"ruleId": advice.id,
"severity": severities[advice.severity],
"type": "VULNERABILITY",
"efforMinutes": 0,
"primaryLocation": {
"message": `${advice.module_name} ${advice.vulnerable_versions}
${advice.title || ''}
Overview:
${advice.overview || ''}
References:
${advice.references || ''}
`,
"filePath": "pnpm-lock.yaml",
},
"secondaryLocations": []
})
}
console.log(JSON.stringify({ issues }, null, 2))
}
main()

19
package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "pnpm-audit-sonar",
"version": "1.0.0",
"description": "Convert PNPM audit to Sonar compatible format",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.celogeek.com/celogeek/pnpm-audit-sonar.git"
},
"bin": {
"pnpm-audit-sonar": "index.js"
},
"author": "Celogeek",
"license": "ISC",
"dependencies": {}
}