Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import threading
import time
import subprocess
import json
try:
# Python 2.x
from urlparse import urlparse
Expand Down Expand Up @@ -88,6 +89,15 @@ def return_code(self):
return self._return_code


def _get_request_json():
if request.is_json:
return request.get_json()
data = request.data
if isinstance(data, bytes):
data = data.decode('utf-8')
return json.loads(data)


def _execute(command: str):
success = False
try:
Expand All @@ -111,7 +121,15 @@ def _execute(command: str):

@app.route('/execute', methods=['POST'])
def execute():
req = request.get_json()
try:
req = _get_request_json()
except Exception as err:
app.logger.exception("_get_request_json err")
return jsonify({
'response': 'Exception: %s' % str(err),
'success': False
})

response, success = _execute(req['command'])

return jsonify({
Expand All @@ -124,7 +142,15 @@ def execute():
def batch_execute():
all_succeeded = True
responses = []
req = request.get_json()
try:
req = _get_request_json()
except Exception as err:
app.logger.exception("_get_request_json err")
return jsonify({
'response': 'Exception: %s' % str(err),
'success': False
})

commands = req['commands']
for command in commands:
response, success = _execute(command)
Expand Down
25 changes: 21 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
flask
flask_redis
flask_redis_sentinel
flask_bootstrap
flask==3.0.3
flask_redis==0.4.0
flask_redis_sentinel==2.0.1
flask_bootstrap==3.3.7.1
async-timeout==4.0.3
blinker==1.8.1
click==8.1.7
dominate==2.9.1
importlib_metadata==7.1.0
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
pip==23.0.1
redis==5.0.4
Redis-Sentinel-Url==1.0.1
setuptools==57.5.0
six==1.16.0
visitor==0.1.3
Werkzeug==3.0.3
wheel==0.43.0
zipp==3.18.1