[Dockerapi] Fix jsonify output

master
andre.peters 2018-02-01 13:38:42 +01:00
parent d6cbe5b10a
commit 0773448b35
1 changed files with 8 additions and 8 deletions

View File

@ -22,7 +22,7 @@ class containers_get(Resource):
containers.update({container.attrs['Id']: container.attrs}) containers.update({container.attrs['Id']: container.attrs})
return containers return containers
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
class container_get(Resource): class container_get(Resource):
def get(self, container_id): def get(self, container_id):
@ -31,7 +31,7 @@ class container_get(Resource):
for container in docker_client.containers.list(all=True, filters={"id": container_id}): for container in docker_client.containers.list(all=True, filters={"id": container_id}):
return container.attrs return container.attrs
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
else: else:
return jsonify(type='danger', msg='no or invalid id defined') return jsonify(type='danger', msg='no or invalid id defined')
@ -44,7 +44,7 @@ class container_post(Resource):
container.stop() container.stop()
return jsonify(type='success', msg='command completed successfully') return jsonify(type='success', msg='command completed successfully')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
elif post_action == 'start': elif post_action == 'start':
try: try:
@ -52,7 +52,7 @@ class container_post(Resource):
container.start() container.start()
return jsonify(type='success', msg='command completed successfully') return jsonify(type='success', msg='command completed successfully')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
elif post_action == 'restart': elif post_action == 'restart':
try: try:
@ -60,7 +60,7 @@ class container_post(Resource):
container.restart() container.restart()
return jsonify(type='success', msg='command completed successfully') return jsonify(type='success', msg='command completed successfully')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
elif post_action == 'exec': elif post_action == 'exec':
@ -72,13 +72,13 @@ class container_post(Resource):
for container in docker_client.containers.list(filters={"id": container_id}): for container in docker_client.containers.list(filters={"id": container_id}):
return container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve list -u '" + request.json['username'].replace("'", "'\\''") + "'"], user='vmail') return container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve list -u '" + request.json['username'].replace("'", "'\\''") + "'"], user='vmail')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
elif request.json['cmd'] == 'sieve_print' and request.json['script_name'] and request.json['username']: elif request.json['cmd'] == 'sieve_print' and request.json['script_name'] and request.json['username']:
try: try:
for container in docker_client.containers.list(filters={"id": container_id}): for container in docker_client.containers.list(filters={"id": container_id}):
return container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve get -u '" + request.json['username'].replace("'", "'\\''") + "' '" + request.json['script_name'].replace("'", "'\\''") + "'"], user='vmail') return container.exec_run(["/bin/bash", "-c", "/usr/local/bin/doveadm sieve get -u '" + request.json['username'].replace("'", "'\\''") + "' '" + request.json['script_name'].replace("'", "'\\''") + "'"], user='vmail')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
elif request.json['cmd'] == 'worker_password' and request.json['raw']: elif request.json['cmd'] == 'worker_password' and request.json['raw']:
try: try:
for container in docker_client.containers.list(filters={"id": container_id}): for container in docker_client.containers.list(filters={"id": container_id}):
@ -89,7 +89,7 @@ class container_post(Resource):
container.restart() container.restart()
return jsonify(type='success', msg='command completed successfully') return jsonify(type='success', msg='command completed successfully')
except Exception as e: except Exception as e:
return jsonify(type='danger', msg=e) return jsonify(type='danger', msg=str(e))
else: else:
return jsonify(type='danger', msg='Unknown command') return jsonify(type='danger', msg='Unknown command')