Explorar el Código

Add secret for git hook and check

JoostSijm hace 6 años
padre
commit
b9cc05ff41
Se han modificado 1 ficheros con 14 adiciones y 1 borrados
  1. 14 1
      app/flaskr.py

+ 14 - 1
app/flaskr.py

@@ -3,19 +3,32 @@
 Website for Craftbroec RR stuff
 """
 
+import hashlib
+import hmac
+
 from subprocess import call
-from flask import jsonify
+from flask import jsonify, abort, request
 from app import app
 
 
+secret = "JdFILOA1O7x6WTcsphlszmeQqU5ngoKZ"
+
+
 @app.route('/')
 def index():
     """Show index page"""
     return jsonify(True)
 
+
 @app.route('/deploy', methods=['POST'])
 def deploy():
     """Run deploy script"""
+    digest = hmac.new(secret, request.data, hashlib.sha1).hexdigest()
+    signature = request.headers['X-Hub-Signature'].split('=', 1)
+    if (len(signature) < 2 or signature[0] != 'sha1'
+            or not hmac.compare_digest(signature[1], digest)):
+        abort(400, 'Invalid signature')
+
     call(["git", "pull"])
     call(["touch", "flask.wsgi"])
     return jsonify(True)