ソースを参照

handle error codes and receive all outputs

Sven Czarnian 3 年 前
コミット
fb40b0aad9
1 ファイル変更7 行追加3 行削除
  1. 7 3
      aman/app.py

+ 7 - 3
aman/app.py

@@ -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')