From a3eddbc20f81a060770cf2242769cfac1db62261 Mon Sep 17 00:00:00 2001 From: Thomas Cole Date: Mon, 17 Jan 2022 21:37:07 -0500 Subject: [PATCH] First Code upload --- .env-sample | 1 + .gitignore | 4 +++- index.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .env-sample create mode 100644 index.js create mode 100644 package.json diff --git a/.env-sample b/.env-sample new file mode 100644 index 0000000..3d91f9b --- /dev/null +++ b/.env-sample @@ -0,0 +1 @@ +SECRET_KEY="" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 40b878d..055395e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules/ \ No newline at end of file +node_modules/ +.env +package-lock.json \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..ae61ad5 --- /dev/null +++ b/index.js @@ -0,0 +1,44 @@ +const express = require('express') +const crypto = require('crypto') +const bodyParser = require('body-parser') +require('dotenv').config() +const SECRET = process.env.SECRET_KEY + +const app = express() +const port = 9000 + +const options = { + inflate: true, + limit: '100kb', + type: 'application/json', +} +app.use(bodyParser.raw(options)) + +app.post('/buildhook', (req, res) => { + const signature = req.headers['x-gitea-signature'] + if (!signature) { + console.error('x-gitea-signature missing') + return res.send() + } + + const hmac = crypto.createHmac('sha256', SECRET) + hmac.update(req.body) + + const payload_signature = hmac.digest('hex') + if (signature !== payload_signature) { + console.error('signature !== payload_signature') + return res.send() + } + + const json = JSON.parse(req.body.toString()) + console.log('json') + console.log(json) + + // SIGNATURES MATCHES, do your thing here. + + res.send('success') +}) + +app.listen(port, () => { + console.log(`Example app listening at http://localhost:${port}`) +}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..039475d --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "expressbuild", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "start": "node index.js", + "dev": "nodemon index.js" + }, + "author": "Thomas Cole", + "license": "MIT", + "dependencies": { + "dotenv": "^14.2.0", + "express": "^4.17.2", + "nodemon": "^2.0.15" + } +}