handle error codes and receive all outputs

This commit is contained in:
Sven Czarnian
2021-12-09 09:19:10 +01:00
parent 9627ae34b7
commit fb40b0aad9

View File

@@ -2,7 +2,7 @@
import json
import os
import subprocess
from subprocess import Popen, PIPE
from flask import Flask, Response, request
from flask_cors import CORS, cross_origin
@@ -54,7 +54,7 @@ def airports():
data = json.dumps({ 'version' : version, 'airports' : retval }, ensure_ascii=True)
return Response(data, status=200, mimetype='application/json')
@app.route('/aman/newuser')
@app.route('/aman/admin/newuser')
def newUser():
toolpath = os.path.join(os.path.join(os.environ['AMAN_PATH'], 'tools'), 'KeyPairCreator.py')
serverKeypath = os.path.join(os.path.join(os.path.join(AMAN.findConfigPath(), 'keys'), 'server'), 'server.key')
@@ -62,7 +62,11 @@ def newUser():
cmd = ['python', toolpath, '--directory=' + clientKeypath, '--publickey=' + serverKeypath]
stdout = subprocess.check_output(cmd)
child = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, _ = child.communicate()
if 0 != child.returncode:
return Response('{}', status=404, mimetype='application/json')
keys = stdout.splitlines()
server = keys[0].decode('ascii')
public = keys[1].decode('ascii')