qiaofeng1227 il y a 2 ans
Parent
commit
e6c313729b
3 fichiers modifiés avec 27 ajouts et 9 suppressions
  1. 1 1
      appmanage/Dockerfile
  2. 25 8
      appmanage/api/service/manage.py
  3. 1 0
      appmanage/api/utils/const.py

+ 1 - 1
appmanage/Dockerfile

@@ -10,7 +10,7 @@ COPY static ./static
 COPY requirements.txt main.py  ./
 COPY requirements.txt main.py  ./
 RUN apt update
 RUN apt update
 
 
-# Install supervisords
+# Install supervisord
 RUN apt install -y supervisor
 RUN apt install -y supervisor
 COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 COPY config/cmd.sh /cmd.sh
 COPY config/cmd.sh /cmd.sh

+ 25 - 8
appmanage/api/service/manage.py

@@ -592,7 +592,9 @@ def app_domain_delete(app_id, domain):
                 'Authorization': token,
                 'Authorization': token,
                 'Content-Type': 'application/json'
                 'Content-Type': 'application/json'
             }
             }
-            requests.delete(url, headers=headers)
+            response = requests.delete(url, headers=headers)
+            if response.json()["error"] != None:
+                raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
             set_domain("", app_id)
             set_domain("", app_id)
         else:
         else:
             proxy_id = proxy["id"]
             proxy_id = proxy["id"]
@@ -626,8 +628,9 @@ def app_domain_delete(app_id, domain):
                 "ssl_forced": False
                 "ssl_forced": False
             }
             }
 
 
-            requests.put(url, data=json.dumps(data), headers=headers)
-            
+            response = requests.put(url, data=json.dumps(data), headers=headers)
+            if response.json()["error"] != None:
+                raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
             domain_set = app_domain_list(app_id)
             domain_set = app_domain_list(app_id)
             default_domain = domain_set['default_domain']
             default_domain = domain_set['default_domain']
             # 如果被删除的域名是默认域名,删除后去剩下域名的第一个
             # 如果被删除的域名是默认域名,删除后去剩下域名的第一个
@@ -692,7 +695,9 @@ def app_domain_update(app_id, domain_old, domain_new):
             "ssl_forced": False
             "ssl_forced": False
         }
         }
 
 
-        requests.put(url, data=json.dumps(data), headers=headers)
+        response = requests.put(url, data=json.dumps(data), headers=headers)
+        if response.json()["error"] != None:
+            raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
         domain_set = app_domain_list(app_id)
         domain_set = app_domain_list(app_id)
         default_domain = domain_set['default_domain']
         default_domain = domain_set['default_domain']
         # 如果被修改的域名是默认域名,修改后也设置为默认域名
         # 如果被修改的域名是默认域名,修改后也设置为默认域名
@@ -758,7 +763,9 @@ def app_domain_add(app_id, domain):
             "ssl_forced": False
             "ssl_forced": False
         }
         }
         myLogger.info_logger(data)
         myLogger.info_logger(data)
-        requests.put(url, data=json.dumps(data), headers=headers)
+        response = requests.put(url, data=json.dumps(data), headers=headers)
+        if response.json()["error"] != None:
+            raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
     else:
     else:
         # 追加
         # 追加
         token = get_token()
         token = get_token()
@@ -793,7 +800,8 @@ def app_domain_add(app_id, domain):
         }
         }
         
         
         response = requests.post(url, data=json.dumps(data), headers=headers)
         response = requests.post(url, data=json.dumps(data), headers=headers)
-        myLogger.info_logger(response.json())
+        if response.json()["error"] != None:
+            raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
         set_domain(domain, app_id)
         set_domain(domain, app_id)
         
         
     return domain
     return domain
@@ -847,6 +855,8 @@ def get_token():
         "secret": password
         "secret": password
     }
     }
     response = requests.post(url, data=json.dumps(param), headers=headers)
     response = requests.post(url, data=json.dumps(param), headers=headers)
+    if response.json()["error"] != None:
+        raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
     token = "Bearer " + response.json()["token"]
     token = "Bearer " + response.json()["token"]
     return token
     return token
 
 
@@ -860,11 +870,13 @@ def get_proxy(app_id):
         'Content-Type': 'application/json'
         'Content-Type': 'application/json'
     }
     }
     response = requests.get(url, headers=headers)
     response = requests.get(url, headers=headers)
+    if response.json()["error"] != None:
+        raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
     for proxy in response.json():
     for proxy in response.json():
         portainer_name = proxy["forward_host"]
         portainer_name = proxy["forward_host"]
         if customer_name == portainer_name:
         if customer_name == portainer_name:
             proxy_host = proxy
             proxy_host = proxy
-            break;
+            break
 
 
     return proxy_host
     return proxy_host
 
 
@@ -878,6 +890,8 @@ def get_proxy_domain(app_id, domain):
         'Content-Type': 'application/json'
         'Content-Type': 'application/json'
     }
     }
     response = requests.get(url, headers=headers)
     response = requests.get(url, headers=headers)
+    if response.json()["error"] != None:
+        raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
     myLogger.info_logger(response.json())
     myLogger.info_logger(response.json())
     for proxy in response.json():
     for proxy in response.json():
         portainer_name = proxy["forward_host"]
         portainer_name = proxy["forward_host"]
@@ -901,6 +915,8 @@ def get_all_domains(app_id):
         'Content-Type': 'application/json'
         'Content-Type': 'application/json'
     }
     }
     response = requests.get(url, headers=headers)
     response = requests.get(url, headers=headers)
+    if response.json()["error"] != None:
+        raise CommandException(const.ERROR_API_NGINX, response.json()["error"]["message"], "")
     for proxy in response.json():
     for proxy in response.json():
         portainer_name = proxy["forward_host"]
         portainer_name = proxy["forward_host"]
         if customer_name == portainer_name:
         if customer_name == portainer_name:
@@ -930,7 +946,8 @@ def set_domain(domain, app_id):
     old_domains = get_all_domains(app_id)
     old_domains = get_all_domains(app_id)
     if domain != "":
     if domain != "":
         if domain not in old_domains:
         if domain not in old_domains:
-            raise CommandException(const.ERROR_CLIENT_PARAM_NOTEXIST, "Binded Domains has no this domain", "") 
+            message = domain + " is not in use"
+            raise CommandException(const.ERROR_CLIENT_PARAM_NOTEXIST, message, "") 
         
         
     customer_name = app_id.split('_')[1]
     customer_name = app_id.split('_')[1]
     app_url = shell_execute.execute_command_output_all("cat /data/apps/" + customer_name +"/.env")["result"]
     app_url = shell_execute.execute_command_output_all("cat /data/apps/" + customer_name +"/.env")["result"]

+ 1 - 0
appmanage/api/utils/const.py

@@ -5,6 +5,7 @@ ERROR_CLIENT_PARAM_BLANK="Client.Parameter.Blank.Error"
 ERROR_CLIENT_PARAM_Format="Client.Parameter.Format.Error"
 ERROR_CLIENT_PARAM_Format="Client.Parameter.Format.Error"
 ERROR_CLIENT_PARAM_NOTEXIST="Client.Parameter.Value.NotExist.Error"
 ERROR_CLIENT_PARAM_NOTEXIST="Client.Parameter.Value.NotExist.Error"
 ERROR_CLIENT_PARAM_REPEAT="Client.Parameter.Value.Repeat.Error"
 ERROR_CLIENT_PARAM_REPEAT="Client.Parameter.Value.Repeat.Error"
+ERROR_API_NGINX="Api.Nginx.Error"
 ERROR_SERVER_COMMAND="Server.Container.Error"
 ERROR_SERVER_COMMAND="Server.Container.Error"
 ERROR_SERVER_SYSTEM="Server.SystemError"
 ERROR_SERVER_SYSTEM="Server.SystemError"
 ERROR_SERVER_RESOURCE="Server.ResourceError"
 ERROR_SERVER_RESOURCE="Server.ResourceError"