-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
34 lines (22 loc) · 779 Bytes
/
main.py
File metadata and controls
34 lines (22 loc) · 779 Bytes
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
import subprocess
from os import path
import flask
from config import secret_token, projects_to_scripts
app = flask.Flask(__name__)
@app.route('/', methods=['POST'])
def index():
if flask.request.headers.get('Authorization') != secret_token:
return flask.abort(401)
project_name = flask.request.json.get("project_name")
if project_name is None:
return flask.abort(400)
script_name = projects_to_scripts.get(project_name)
if script_name is None:
return flask.abort(404)
try:
subprocess.run([path.join('scripts/', script_name)], check=True)
except subprocess.CalledProcessError:
return flask.abort(500)
return 'Ok'
if __name__ == "__main__":
app.run(host='0.0.0.0', port=2010, threaded=False)