handle error codes and receive all outputs
This commit is contained in:
10
aman/app.py
10
aman/app.py
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
from flask import Flask, Response, request
|
from flask import Flask, Response, request
|
||||||
from flask_cors import CORS, cross_origin
|
from flask_cors import CORS, cross_origin
|
||||||
@@ -54,7 +54,7 @@ def airports():
|
|||||||
data = json.dumps({ 'version' : version, 'airports' : retval }, ensure_ascii=True)
|
data = json.dumps({ 'version' : version, 'airports' : retval }, ensure_ascii=True)
|
||||||
return Response(data, status=200, mimetype='application/json')
|
return Response(data, status=200, mimetype='application/json')
|
||||||
|
|
||||||
@app.route('/aman/newuser')
|
@app.route('/aman/admin/newuser')
|
||||||
def newUser():
|
def newUser():
|
||||||
toolpath = os.path.join(os.path.join(os.environ['AMAN_PATH'], 'tools'), 'KeyPairCreator.py')
|
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')
|
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]
|
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()
|
keys = stdout.splitlines()
|
||||||
server = keys[0].decode('ascii')
|
server = keys[0].decode('ascii')
|
||||||
public = keys[1].decode('ascii')
|
public = keys[1].decode('ascii')
|
||||||
|
|||||||
Reference in New Issue
Block a user