Add auth and blacklist APIs

This commit is contained in:
MICHAEL JACKSON
2017-11-11 12:18:13 -08:00
parent cc70428986
commit 0e1f26849b
35 changed files with 1166 additions and 339 deletions

View File

@ -1,15 +1,26 @@
function checkBlacklist(blacklist) {
return function(req, res, next) {
// Do not allow packages that have been blacklisted.
if (blacklist.includes(req.packageName)) {
res
.status(403)
.type('text')
.send(`Package "${req.packageName}" is blacklisted`)
} else {
next()
const BlacklistAPI = require('../BlacklistAPI')
function checkBlacklist(req, res, next) {
BlacklistAPI.containsPackage(req.packageName).then(
blacklisted => {
// Disallow packages that have been blacklisted.
if (blacklisted) {
res
.status(403)
.type('text')
.send(`Package "${req.packageName}" is blacklisted`)
} else {
next()
}
},
error => {
console.error(error)
res.status(500).send({
error: 'Unable to fetch the blacklist'
})
}
}
)
}
module.exports = checkBlacklist