-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_webhook.py
47 lines (39 loc) · 1.29 KB
/
server_webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
from flask import *
from werkzeug.middleware.proxy_fix import ProxyFix
import os
from dotenv import load_dotenv
import hmac
import hashlib
FLASK_ENV = os.getenv("FLASK_ENV", "development")
print(FLASK_ENV)
load_dotenv(f"./env/.env.{FLASK_ENV}")
app = Flask(__name__)
app.wsgi_app = ProxyFix(
app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1
)
@app.route('/server-webhook', methods=["POST"])
def otlplus_redeploy():
webhook_secret = os.getenv("WEBHOOK_SECRET").encode()
signature = 'sha256=' + hmac.new(webhook_secret, request.data, hashlib.sha256).hexdigest()
print(signature)
print( request.headers['X-Hub-Signature-256'])
if 'X-Hub-Signature-256' not in request.headers or not hmac.compare_digest(
signature, request.headers['X-Hub-Signature-256']
):
abort(403)
os.spawnl(
os.P_NOWAIT,
"/usr/bin/sudo",
"sudo",
"/bin/bash",
"/home/otlplus/server/deploy.sh",
"-e", "dev"
)
return "Done", 200
@app.route('/server-webhook-status', methods=["GET"])
def clubs_stage_redeploy():
# os.spawnl(os.P_NOWAIT, "/bin/bash", "/bin/bash", "/home/otlplus/server/deploy.sh -e dev")
return "Done", 200
if __name__ == '__main__':
app.run(host="127.0.0.1", threaded=True, port=5000)