mirror of https://github.com/Aidaho12/haproxy-wi
v8.2: Remove unnecessary blank lines and exception handling
Removed multiple unnecessary blank lines across various files to maintain code cleanliness and readability. Simplified exception handling in the `roxywi/auth.py` module and updated the import statements in `ha/routes.py`. Added a timeout parameter to the requests call in `alerting.py` for better error management.pull/399/head
parent
18f9b11f35
commit
a9aa9f2436
|
@ -1,6 +1,6 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from flask import redirect, url_for, abort, g
|
from flask import abort, g
|
||||||
|
|
||||||
import app.modules.roxywi.auth as roxywi_auth
|
import app.modules.roxywi.auth as roxywi_auth
|
||||||
import app.modules.roxywi.common as roxywi_common
|
import app.modules.roxywi.common as roxywi_common
|
||||||
|
@ -25,7 +25,8 @@ def get_user_params(virt=0, disable=0):
|
||||||
try:
|
try:
|
||||||
user_params = roxywi_common.get_users_params(virt=virt, disable=disable, service=kwargs.get('service'))
|
user_params = roxywi_common.get_users_params(virt=virt, disable=disable, service=kwargs.get('service'))
|
||||||
g.user_params = user_params
|
g.user_params = user_params
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
return abort(401)
|
return abort(401)
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
return decorated_views
|
return decorated_views
|
||||||
|
|
|
@ -118,10 +118,7 @@ def do_login(user_params: dict, next_url: str):
|
||||||
except Exception:
|
except Exception:
|
||||||
user_group_name = ''
|
user_group_name = ''
|
||||||
|
|
||||||
try:
|
roxywi_common.logging('Roxy-WI server', f' user: {user_params["name"]}, group: {user_group_name} login', roxywi=1)
|
||||||
roxywi_common.logging('RMON server', f' user: {user_params["name"]}, group: {user_group_name} login', roxywi=1)
|
|
||||||
except Exception as e:
|
|
||||||
print(f'error: {e}')
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,7 @@ def mm_send_mess(mess, level, server_ip=None, service_id=None, alert_type=None,
|
||||||
values = f'{{"channel": "{channel}", "username": "Roxy-WI", "attachments": [{attach}]}}'
|
values = f'{{"channel": "{channel}", "username": "Roxy-WI", "attachments": [{attach}]}}'
|
||||||
proxy_dict = common.return_proxy_dict()
|
proxy_dict = common.return_proxy_dict()
|
||||||
try:
|
try:
|
||||||
requests.post(token, headers=headers, data=str(values), proxies=proxy_dict)
|
requests.post(token, headers=headers, data=str(values), proxies=proxy_dict, timeout=15)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
roxywi_common.logging('Roxy-WI server', str(e), roxywi=1)
|
roxywi_common.logging('Roxy-WI server', str(e), roxywi=1)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import render_template, g, request, jsonify
|
from flask import render_template, g, jsonify
|
||||||
from flask_jwt_extended import jwt_required
|
from flask_jwt_extended import jwt_required
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,6 @@ def update_user_password(user_id):
|
||||||
return ErrorResponse(error=str(e)).model_dump(mode='json'), 501
|
return ErrorResponse(error=str(e)).model_dump(mode='json'), 501
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/services/<int:user_id>', methods=['GET', 'POST'])
|
@bp.route('/services/<int:user_id>', methods=['GET', 'POST'])
|
||||||
def show_user_services(user_id):
|
def show_user_services(user_id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
|
|
@ -454,7 +454,6 @@ class HAVIPView(MethodView):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot create VIP')
|
return roxywi_common.handler_exceptions_for_json_data(e, 'Cannot create VIP')
|
||||||
|
|
||||||
|
|
||||||
@validate(body=HAClusterVIP)
|
@validate(body=HAClusterVIP)
|
||||||
def put(self, service: str, cluster_id: int, vip_id: int, body: HAClusterVIP):
|
def put(self, service: str, cluster_id: int, vip_id: int, body: HAClusterVIP):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1258,7 +1258,6 @@ class GlobalSectionView(HaproxySectionView):
|
||||||
"""
|
"""
|
||||||
return super().get(service, 'global', 'global', server_id)
|
return super().get(service, 'global', 'global', server_id)
|
||||||
|
|
||||||
|
|
||||||
@validate(body=HaproxyGlobalRequest, query=GenerateConfigRequest)
|
@validate(body=HaproxyGlobalRequest, query=GenerateConfigRequest)
|
||||||
def put(self, service: Literal['haproxy'], server_id: Union[int, str], body: HaproxyGlobalRequest):
|
def put(self, service: Literal['haproxy'], server_id: Union[int, str], body: HaproxyGlobalRequest):
|
||||||
"""
|
"""
|
||||||
|
@ -1443,7 +1442,6 @@ class DefaultsSectionView(HaproxySectionView):
|
||||||
"""
|
"""
|
||||||
return super().get(service, 'defaults', 'defaults', server_id)
|
return super().get(service, 'defaults', 'defaults', server_id)
|
||||||
|
|
||||||
|
|
||||||
@validate(body=HaproxyDefaultsRequest, query=GenerateConfigRequest)
|
@validate(body=HaproxyDefaultsRequest, query=GenerateConfigRequest)
|
||||||
def put(self, service: Literal['haproxy'], server_id: Union[int, str], body: HaproxyDefaultsRequest):
|
def put(self, service: Literal['haproxy'], server_id: Union[int, str], body: HaproxyDefaultsRequest):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -456,7 +456,6 @@ class ServiceConfigView(MethodView):
|
||||||
if body.action != 'test':
|
if body.action != 'test':
|
||||||
config_mod.diff_config(body.config_local_path, cfg)
|
config_mod.diff_config(body.config_local_path, cfg)
|
||||||
|
|
||||||
|
|
||||||
return DataStrResponse(data=stderr).model_dump(mode='json'), 201
|
return DataStrResponse(data=stderr).model_dump(mode='json'), 201
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ class PortScannerView(MethodView):
|
||||||
|
|
||||||
return jsonify(model_to_dict(ps_settings, recurse=False, exclude=[PortScannerSettings.user_group_id]))
|
return jsonify(model_to_dict(ps_settings, recurse=False, exclude=[PortScannerSettings.user_group_id]))
|
||||||
|
|
||||||
|
|
||||||
@validate(body=PortScannerRequest)
|
@validate(body=PortScannerRequest)
|
||||||
def post(self, server_id: Union[int, str], body: PortScannerRequest):
|
def post(self, server_id: Union[int, str], body: PortScannerRequest):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue