Skip to content

Commit

Permalink
Merge pull request #64 from greenkeeperio/npm/add_license_and_author
Browse files Browse the repository at this point in the history
Npm/add license and author
  • Loading branch information
hulkoba committed Jun 25, 2019
2 parents 91c6426 + d292cb7 commit f4fddf2
Show file tree
Hide file tree
Showing 19 changed files with 1,228 additions and 1,205 deletions.
22 changes: 11 additions & 11 deletions lib/deprecate-node-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ module.exports.attributes = {
name: 'deprecateNode'
}

function deprecateNodeEvent (server, {env, channel}, next) {
function deprecateNodeEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/deprecate-node',
config: {
pre: [{method: (request, reply) => {
pre: [{ method: (request, reply) => {
if (request.headers['bearer-token'] === env.BEARER_TOKEN) {
return reply.continue()
}
return reply(Boom.unauthorized())
}}]
} }]
},
handler
})

async function handler (request, reply) {
if (!_.get(request, 'payload.repositoryFullName')) return reply({error: 'repositoryFullName missing'}).code(400)
if (!_.get(request, 'payload.nodeVersion')) return reply({error: 'nodeVersion missing'}).code(400)
if (!_.get(request, 'payload.codeName')) return reply({error: 'codeName missing'}).code(400)
if (!_.get(request, 'payload.newLowestVersion')) return reply({error: 'newLowestVersion missing'}).code(400)
if (!_.get(request, 'payload.newLowestCodeName')) return reply({error: 'newLowestCodeName missing'}).code(400)
if (!_.get(request, 'payload.repositoryFullName')) return reply({ error: 'repositoryFullName missing' }).code(400)
if (!_.get(request, 'payload.nodeVersion')) return reply({ error: 'nodeVersion missing' }).code(400)
if (!_.get(request, 'payload.codeName')) return reply({ error: 'codeName missing' }).code(400)
if (!_.get(request, 'payload.newLowestVersion')) return reply({ error: 'newLowestVersion missing' }).code(400)
if (!_.get(request, 'payload.newLowestCodeName')) return reply({ error: 'newLowestCodeName missing' }).code(400)
// `request.payload.announcementURL` is optional

const job = {
Expand All @@ -42,7 +42,7 @@ function deprecateNodeEvent (server, {env, channel}, next) {
}

try {
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), {priority: 3})
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), { priority: 3 })
} catch (err) {
rollbar.error(err, _.assign({}, request.raw.req, {
socket: {
Expand All @@ -52,10 +52,10 @@ function deprecateNodeEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(500)
return reply({ error: true }).code(500)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}

next()
Expand Down
30 changes: 15 additions & 15 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const envalid = require('envalid')
const {str, num, url, bool} = envalid
const { str, num, url, bool } = envalid

module.exports = envalid.cleanEnv(process.env, {
PORT: num({default: 5000}),
WEBHOOKS_SECRET: str({devDefault: 'YOLO'}),
NPMHOOKS_SECRET: str({devDefault: 'SWAG'}),
QUEUE_NAME: str({default: 'events'}),
AMQP_URL: url({devDefault: 'amqp://localhost?heartbeat=15'}),
NODE_ENV: str({choices: ['development', 'staging', 'production'], devDefault: 'development'}),
ROLLBAR_TOKEN_HOOKS: str({devDefault: ''}),
STATSD_HOST: str({default: '172.17.0.1'}),
BEARER_TOKEN: str({devDefault: 'PIZZA'}),
IS_ENTERPRISE: bool({default: false}),
NEXUS_SECRET: str({devDefault: 'test', default: ''}),
NEXUS_URL: str({devDefault: 'http://127.0.0.1:8081/repository', default: ''}),
NEXUS_REPOSITORY: str({devDefault: 'my-npm', default: ''}),
NEXUS_INSTALLATION: str({devDefault: '1', default: ''})
PORT: num({ default: 5000 }),
WEBHOOKS_SECRET: str({ devDefault: 'YOLO' }),
NPMHOOKS_SECRET: str({ devDefault: 'SWAG' }),
QUEUE_NAME: str({ default: 'events' }),
AMQP_URL: url({ devDefault: 'amqp://localhost?heartbeat=15' }),
NODE_ENV: str({ choices: ['development', 'staging', 'production'], devDefault: 'development' }),
ROLLBAR_TOKEN_HOOKS: str({ devDefault: '' }),
STATSD_HOST: str({ default: '172.17.0.1' }),
BEARER_TOKEN: str({ devDefault: 'PIZZA' }),
IS_ENTERPRISE: bool({ default: false }),
NEXUS_SECRET: str({ devDefault: 'test', default: '' }),
NEXUS_URL: str({ devDefault: 'http://127.0.0.1:8081/repository', default: '' }),
NEXUS_REPOSITORY: str({ devDefault: 'my-npm', default: '' }),
NEXUS_INSTALLATION: str({ devDefault: '1', default: '' })
})
12 changes: 6 additions & 6 deletions lib/github-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports.attributes = {
name: 'github'
}

function githubEvent (server, {env, channel}, next) {
function githubEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/github',
Expand All @@ -68,20 +68,20 @@ function githubEvent (server, {env, channel}, next) {
async function handler (request, reply) {
const eventName = request.headers['x-github-event']

if (_.includes(blacklist, eventName)) return reply({ok: true}).code(202)
if (_.includes(blacklist, eventName)) return reply({ ok: true }).code(202)

const event = githubEvents[eventName] || {
priority: 1
}

const {payload} = request
const { payload } = request
const hmacPayload = crypto.createHmac('sha1', env.WEBHOOKS_SECRET)
.update(payload)
.digest('hex')

const signature = request.headers['x-hub-signature']
if (`sha1=${hmacPayload}` !== signature) {
return reply({error: true}).code(403)
return reply({ error: true }).code(403)
}

const parsedPayload = JSON.parse(payload.toString())
Expand All @@ -101,10 +101,10 @@ function githubEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(500)
return reply({ error: true }).code(500)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}

next()
Expand Down
16 changes: 8 additions & 8 deletions lib/nexus-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports.attributes = {
name: 'nexus'
}

function nexusEvent (server, {env, channel}, next) {
function nexusEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/nexus/',
Expand All @@ -31,7 +31,7 @@ function nexusEvent (server, {env, channel}, next) {
const nexusInstallation = env.NEXUS_INSTALLATION

if (!nexusSecret || !nexusUrl || !nexusRepository || !nexusInstallation) {
return reply({ok: false}).code(503) // Service Unavailable
return reply({ ok: false }).code(503) // Service Unavailable
}

const payload = request.payload.toString()
Expand All @@ -42,19 +42,19 @@ function nexusEvent (server, {env, channel}, next) {
.digest('hex')

if (signature !== hmacDigest) {
return reply({ok: false}).code(403)
return reply({ ok: false }).code(403)
}

let update
try {
update = JSON.parse(payload)
// we can only parse out the version on here
if (update.action !== 'CREATED') {
return reply({ok: true}).code(200)
return reply({ ok: true }).code(200)
}
} catch (e) {
console.log(e)
return reply({error: true}).code(401)
return reply({ error: true }).code(401)
}

const name = update.asset.name.split('/-/')[0]
Expand Down Expand Up @@ -82,7 +82,7 @@ function nexusEvent (server, {env, channel}, next) {
}

try {
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), {priority: 1})
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), { priority: 1 })
} catch (err) {
console.log('rollbar', err)
rollbar.error(err, _.assign({}, request.raw.req, {
Expand All @@ -93,10 +93,10 @@ function nexusEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(501)
return reply({ error: true }).code(501)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}
next()
}
18 changes: 8 additions & 10 deletions lib/npm-event.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const crypto = require('crypto')

const _ = require('lodash')

const rollbar = require('./rollbar')

module.exports = npmEvent
module.exports.attributes = {
name: 'npm'
}

function npmEvent (server, {env, channel}, next) {
function npmEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/npm/{installation}',
Expand All @@ -29,23 +27,23 @@ function npmEvent (server, {env, channel}, next) {
.update(installation)
.digest('hex')

const {payload} = request
const { payload } = request
const hmacPayload = crypto.createHmac('sha256', secret)
.update(payload)
.digest('hex')

const signature = request.headers['x-npm-signature']
if (`sha256=${hmacPayload}` !== signature) {
return reply({error: true}).code(403)
return reply({ error: true }).code(403)
}

var parsedPayload, distTags, versions
try {
parsedPayload = JSON.parse(payload.toString()).payload
distTags = parsedPayload['dist-tags']
versions = _.mapValues(parsedPayload.versions, v => _.pick(v, ['gitHead', 'repository']))
versions = _.mapValues(parsedPayload.versions, version => _.pick(version, ['gitHead', 'repository', 'license', '_npmUser']))
} catch (e) {
return reply({error: true}).code(401)
return reply({ error: true }).code(401)
}

const job = {
Expand All @@ -58,7 +56,7 @@ function npmEvent (server, {env, channel}, next) {
}

try {
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), {priority: 1})
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), { priority: 1 })
} catch (err) {
rollbar.error(err, _.assign({}, request.raw.req, {
socket: {
Expand All @@ -68,10 +66,10 @@ function npmEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(500)
return reply({ error: true }).code(500)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}

next()
Expand Down
14 changes: 7 additions & 7 deletions lib/reset-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ module.exports.attributes = {
name: 'reset'
}

function resetEvent (server, {env, channel}, next) {
function resetEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/reset',
config: {
pre: [{method: (request, reply) => {
pre: [{ method: (request, reply) => {
if (request.headers['bearer-token'] === env.BEARER_TOKEN) {
return reply.continue()
}
return reply(Boom.unauthorized())
}}]
} }]
},
handler
})

async function handler (request, reply) {
if (!_.get(request, 'payload.repositoryFullName')) return reply({error: 'repositoryFullName missing'}).code(400)
if (!_.get(request, 'payload.repositoryFullName')) return reply({ error: 'repositoryFullName missing' }).code(400)

const job = {
name: 'reset',
Expand All @@ -33,7 +33,7 @@ function resetEvent (server, {env, channel}, next) {
}

try {
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), {priority: 5})
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), { priority: 5 })
} catch (err) {
rollbar.error(err, _.assign({}, request.raw.req, {
socket: {
Expand All @@ -43,10 +43,10 @@ function resetEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(500)
return reply({ error: true }).code(500)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}

next()
Expand Down
4 changes: 2 additions & 2 deletions lib/rollbar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {resolve} = require('path')
const { resolve } = require('path')

const Rollbar = require('rollbar')

Expand All @@ -18,5 +18,5 @@ if (enabled) {
exitOnUncaughtException: true
})
} else {
module.exports = new Rollbar({enabled: false})
module.exports = new Rollbar({ enabled: false })
}
10 changes: 5 additions & 5 deletions lib/stripe-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ module.exports.attributes = {
name: 'stripe'
}

function stripeEvent (server, {env, channel}, next) {
function stripeEvent (server, { env, channel }, next) {
server.route({
method: 'POST',
path: '/stripe',
handler
})

async function handler (request, reply) {
if (!_.get(request, 'payload.id')) return reply({error: 'id missing'}).code(400)
if (!_.get(request, 'payload.id')) return reply({ error: 'id missing' }).code(400)

const job = {
name: 'stripe-event',
id: request.payload.id
}

try {
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), {priority: 5})
await channel.sendToQueue(env.QUEUE_NAME, Buffer.from(JSON.stringify(job)), { priority: 5 })
} catch (err) {
rollbar.error(err, _.assign({}, request.raw.req, {
socket: {
Expand All @@ -33,10 +33,10 @@ function stripeEvent (server, {env, channel}, next) {
remoteAddress: request.info.remoteAddress
}
}))
return reply({error: true}).code(500)
return reply({ error: true }).code(500)
}

reply({ok: true}).code(202)
reply({ ok: true }).code(202)
}

next()
Expand Down
Loading

0 comments on commit f4fddf2

Please sign in to comment.