mirror of https://github.com/Aidaho12/haproxy-wi
v8.2: Fix whitespace inconsistencies across various modules
Refactor multiple files to correct spacing issues, including extra blank lines, misaligned parameters, and inconsistent indentation. These changes improve code readability and maintain coding standards without altering functionality.pull/399/head
parent
292ca51cc7
commit
7ec162244f
|
@ -108,6 +108,7 @@ register_api(UserView, 'user', '/user', 'user_id')
|
|||
register_api_with_group(UserGroupView, 'user_group', 'user', 'groups')
|
||||
bp.add_url_rule('/user/roles', view_func=UserRoles.as_view('roles'))
|
||||
|
||||
|
||||
def register_api_channel(view, endpoint, url_beg, pk='receiver', pk_type='int', pk_end='channel_id', pk_type_end='int'):
|
||||
view_func = view.as_view(endpoint, True)
|
||||
bp.add_url_rule(f'/{url_beg}/<any(telegram, slack, pd, mm):{pk}>', view_func=view_func, methods=['POST'])
|
||||
|
|
|
@ -562,6 +562,7 @@ def update_db_v_7_4():
|
|||
else:
|
||||
print("An error occurred:", e)
|
||||
|
||||
|
||||
def update_db_v_8():
|
||||
try:
|
||||
migrate(
|
||||
|
|
|
@ -174,7 +174,7 @@ def is_tool(name):
|
|||
return True if is_tool_installed is not None else False
|
||||
|
||||
|
||||
def wrap_line(content: str, css_class: str="line") -> str:
|
||||
def wrap_line(content: str, css_class: str = "line") -> str:
|
||||
"""
|
||||
Wraps the provided content into a div HTML element with the given CSS class.
|
||||
"""
|
||||
|
|
|
@ -6,8 +6,8 @@ from app.modules.common.common import return_nice_path
|
|||
|
||||
|
||||
SECTION_NAMES = (
|
||||
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
||||
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
||||
'global', 'listen', 'frontend', 'backend', 'cache', 'defaults', '#HideBlockStart',
|
||||
'#HideBlockEnd', 'peers', 'resolvers', 'userlist', 'http-errors'
|
||||
)
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ def _extract_section_name(line: str):
|
|||
|
||||
:param line: The line to extract the section name from.
|
||||
:return: The extracted section name as a string if it starts with one of the SECTION_NAMES,
|
||||
None otherwise.
|
||||
None otherwise.
|
||||
"""
|
||||
line = line.strip()
|
||||
if line.startswith(SECTION_NAMES):
|
||||
|
|
|
@ -79,6 +79,7 @@ def select_gits(**kwargs):
|
|||
else:
|
||||
return query_res
|
||||
|
||||
|
||||
def select_backups(**kwargs):
|
||||
if kwargs.get("server") is not None and kwargs.get("rserver") is not None:
|
||||
query = Backup.select().where((Backup.server == kwargs.get("server")) & (Backup.rhost == kwargs.get("rserver")))
|
||||
|
|
|
@ -18,7 +18,7 @@ def get_user_receiver_by_group(receiver: str, group: int):
|
|||
out_error(e)
|
||||
|
||||
|
||||
def get_receiver_by_ip(receiver:str, ip: str):
|
||||
def get_receiver_by_ip(receiver: str, ip: str):
|
||||
model = models[receiver]
|
||||
try:
|
||||
return model.select().join(Server, on=(Server.group_id == model.group_id)).where(Server.ip == ip).execute()
|
||||
|
|
|
@ -18,7 +18,6 @@ def select_user_name():
|
|||
return query_res
|
||||
|
||||
|
||||
|
||||
def update_user_name(user_name):
|
||||
user_update = UserName.update(UserName=user_name)
|
||||
try:
|
||||
|
|
|
@ -95,7 +95,7 @@ def check_in_ldap(user, password):
|
|||
except ldap.SERVER_DOWN:
|
||||
raise Exception('error: LDAP server is down')
|
||||
except ldap.LDAPError as e:
|
||||
if type(e.message) == dict and 'desc' in e.message:
|
||||
if isinstance(e.message, dict) and 'desc' in e.message:
|
||||
raise Exception(f'error: {e.message["desc"]}')
|
||||
else:
|
||||
raise Exception(f'error: {e}')
|
||||
|
|
|
@ -68,7 +68,6 @@ def check_user_group_for_socket(user_id: int, group_id: int) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
|
||||
def check_is_server_in_group(server_ip: str) -> bool:
|
||||
group_id = get_user_group(id=1)
|
||||
servers = server_sql.select_servers(server=server_ip)
|
||||
|
@ -319,6 +318,7 @@ def is_user_has_access_to_group(user_id: int, group_id: int) -> None:
|
|||
if not user_sql.check_user_group(user_id, group_id) and g.user_params['role'] != 1:
|
||||
raise RoxywiGroupMismatch
|
||||
|
||||
|
||||
def handle_json_exceptions(ex: Exception, message: str, server_ip='Roxy-WI server') -> dict:
|
||||
logging(server_ip, f'{message}: {ex}', login=1, roxywi=1)
|
||||
return ErrorResponse(error=f'{message}: {ex}').model_dump(mode='json')
|
||||
|
|
|
@ -85,8 +85,7 @@ def create_ssh_cred(name: str, password: str, group: int, username: str, enable:
|
|||
return IdResponse(id=last_id).model_dump(mode='json')
|
||||
else:
|
||||
data = render_template('ajax/new_ssh.html',
|
||||
groups=group_sql.select_groups(), sshs=cred_sql.select_ssh(name=name), lang=lang, adding=1
|
||||
)
|
||||
groups=group_sql.select_groups(), sshs=cred_sql.select_ssh(name=name), lang=lang, adding=1)
|
||||
return IdDataResponse(id=last_id, data=data).model_dump(mode='json')
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ def create_s3_backup_inv(data: S3BackupRequest, tag: str) -> None:
|
|||
def create_git_backup_inv(data: GitBackupRequest, server_ip: str, service: str, del_job: int = 0) -> None:
|
||||
service_config_dir = sql.get_setting(service + '_dir')
|
||||
ssh_settings = ssh_mod.return_ssh_keys_path(server_ip, id=data.cred_id)
|
||||
print('del_job',del_job)
|
||||
inv = {"server": {"hosts": {}}}
|
||||
inv["server"]["hosts"][server_ip] = {
|
||||
"REPO": data.repo,
|
||||
|
@ -74,7 +73,6 @@ def create_git_backup_inv(data: GitBackupRequest, server_ip: str, service: str,
|
|||
raise Exception(f'error: {e}')
|
||||
|
||||
|
||||
|
||||
def create_backup(json_data: BackupRequest, is_api: bool) -> tuple:
|
||||
if backup_sql.check_exists_backup(json_data.server):
|
||||
raise Exception(f'warning: Backup job for {json_data.server} already exists')
|
||||
|
|
|
@ -37,17 +37,6 @@ def get_correct_service_name(service: str, server_id: int) -> str:
|
|||
return service
|
||||
|
||||
|
||||
# def check_haproxy_version(server_ip):
|
||||
# hap_sock_p = sql.get_setting('haproxy_sock_port')
|
||||
# ver = ""
|
||||
# cmd = f"echo 'show info' |nc {server_ip} {hap_sock_p} |grep Version |awk '{{print $2}}'"
|
||||
# output, stderr = server_mod.subprocess_execute(cmd)
|
||||
# for line in output:
|
||||
# ver = line
|
||||
#
|
||||
# return ver
|
||||
|
||||
|
||||
def is_protected(server_ip: str, action: str) -> None:
|
||||
"""
|
||||
Check if the server is protected and the user has the required role.
|
||||
|
@ -192,7 +181,6 @@ def check_service_config(server_ip: str, server_id: int, service: str) -> None:
|
|||
raise Exception(e)
|
||||
|
||||
|
||||
|
||||
def overview_backends(server_ip: str, service: str) -> Union[str, dict]:
|
||||
import app.modules.config.config as config_mod
|
||||
|
||||
|
@ -273,26 +261,3 @@ def get_stat_page(server_ip: str, service: str, group_id: int) -> str:
|
|||
return render_template('ajax/nginx_stats.html', out=servers_with_status, lang=lang)
|
||||
else:
|
||||
return data.decode('utf-8')
|
||||
|
||||
|
||||
# def show_service_version(server_ip: str, service: str) -> str:
|
||||
# if service == 'haproxy':
|
||||
# return check_haproxy_version(server_ip)
|
||||
#
|
||||
# server_id = server_sql.select_server_id_by_ip(server_ip)
|
||||
# service_name = get_correct_service_name(service, server_id)
|
||||
# is_dockerized = service_sql.select_service_setting(server_id, service, 'dockerized')
|
||||
#
|
||||
# if is_dockerized == '1':
|
||||
# container_name = sql.get_setting(f'{service}_container_name')
|
||||
# if service == 'apache':
|
||||
# cmd = f'docker exec -it {container_name} /usr/local/apache2/bin/httpd -v 2>&1|head -1|awk -F":" \'{{print $2}}\''
|
||||
# else:
|
||||
# cmd = f'docker exec -it {container_name} /usr/sbin/{service_name} -v 2>&1|head -1|awk -F":" \'{{print $2}}\''
|
||||
# else:
|
||||
# cmd = [f'sudo /usr/sbin/{service_name} -v|head -1|awk -F":" \'{{print $2}}\'']
|
||||
#
|
||||
# try:
|
||||
# return server_mod.ssh_command(server_ip, cmd, timeout=5)
|
||||
# except Exception as e:
|
||||
# return f'{e}'
|
||||
|
|
|
@ -4,7 +4,7 @@ import app.modules.db.sql as sql
|
|||
from app.modules.service.installation import run_ansible
|
||||
|
||||
|
||||
def generate_exporter_inc(server_ip: str,ver: str, exporter: str) -> object:
|
||||
def generate_exporter_inc(server_ip: str, ver: str, exporter: str) -> object:
|
||||
inv = {"server": {"hosts": {}}}
|
||||
server_ips = [server_ip]
|
||||
inv['server']['hosts'][server_ip] = {
|
||||
|
|
|
@ -45,7 +45,7 @@ def create_cluster(cluster: HAClusterRequest, group_id: int) -> int:
|
|||
except Exception as e:
|
||||
raise Exception(f'error: Cannot add service {service}: {e}')
|
||||
|
||||
if not servers is None:
|
||||
if servers is not None:
|
||||
try:
|
||||
router_id = ha_sql.create_ha_router(cluster_id, default=1)
|
||||
except Exception as e:
|
||||
|
@ -62,7 +62,7 @@ def create_cluster(cluster: HAClusterRequest, group_id: int) -> int:
|
|||
except Exception as e:
|
||||
raise Exception(f'error: Cannon add VIP: {e}')
|
||||
|
||||
if cluster.virt_server and not servers is None:
|
||||
if cluster.virt_server and servers is not None:
|
||||
add_or_update_virt(cluster, servers, cluster_id, vip_id, group_id)
|
||||
|
||||
return int(cluster_id)
|
||||
|
|
|
@ -45,7 +45,6 @@ def _return_listener_servers(listener_id: int, group_id=None):
|
|||
return servers, listener
|
||||
|
||||
|
||||
|
||||
def listener_actions(listener_id: int, action: str, group_id: int) -> None:
|
||||
cmd = f'sudo systemctl {action} keepalived-udp-{listener_id}.service'
|
||||
try:
|
||||
|
|
|
@ -19,12 +19,14 @@ from app.views.service.haproxy_section_views import (GlobalSectionView, Defaults
|
|||
|
||||
get_config = roxy_wi_tools.GetConfigVar()
|
||||
|
||||
|
||||
def register_api_id_ip(view, endpoint, url: str = '', methods: list = ['GET', 'POST']):
|
||||
for point in ('_id', '_ip'):
|
||||
view_func = view.as_view(f'{endpoint}_{point}')
|
||||
pk = 'int:' if point == '_id' else ''
|
||||
bp.add_url_rule(f'/<any(haproxy, nginx, apache, keepalived):service>/<{pk}server_id>{url}', view_func=view_func, methods=methods)
|
||||
|
||||
|
||||
register_api_id_ip(ListenSectionView, 'haproxy_section_post_a', '/section/<any(listen, frontend, backend):section_type>', methods=['POST'])
|
||||
register_api_id_ip(ListenSectionView, 'haproxy_section_a', '/section/<any(listen, frontend, backend):section_type>/<section_name>', methods=['GET', 'PUT', 'DELETE'])
|
||||
register_api_id_ip(UserListSectionView, 'haproxy_userlist_post_a', '/section/userlist', methods=['POST'])
|
||||
|
|
|
@ -7,6 +7,7 @@ import app.modules.tools.alerting as alerting
|
|||
import app.modules.roxywi.common as roxywi_common
|
||||
from app.views.channel.views import ChannelView
|
||||
|
||||
|
||||
def register_api_channel(view, endpoint, url_beg, pk='receiver', pk_type='int', pk_end='channel_id', pk_type_end='int'):
|
||||
view_func = view.as_view(endpoint, False)
|
||||
bp.add_url_rule(f'/{url_beg}/<any(telegram, slack, pd, mm):{pk}>', view_func=view_func, methods=['POST'])
|
||||
|
|
|
@ -26,6 +26,7 @@ bp.add_url_rule(
|
|||
methods=['POST'],
|
||||
)
|
||||
|
||||
|
||||
@bp.before_request
|
||||
@jwt_required()
|
||||
def before_request():
|
||||
|
|
|
@ -225,6 +225,7 @@ def service_history(service, server_ip):
|
|||
|
||||
return render_template('history.html', **kwargs)
|
||||
|
||||
|
||||
@bp.route('/internal/show_version')
|
||||
@cache.cached()
|
||||
def show_roxywi_version():
|
||||
|
|
|
@ -26,6 +26,7 @@ bp.add_url_rule('/<service>/<int:server_id>/backend', view_func=ServiceBackendVi
|
|||
bp.add_url_rule('/<service>/<server_id>/status', view_func=ServiceView.as_view('service_ip'), methods=['GET'])
|
||||
bp.add_url_rule('/<service>/<int:server_id>/status', view_func=ServiceView.as_view('service'), methods=['GET'])
|
||||
|
||||
|
||||
@bp.before_request
|
||||
@jwt_required()
|
||||
def before_request():
|
||||
|
|
|
@ -10,5 +10,6 @@ def before_request():
|
|||
""" Protect all the admin endpoints. """
|
||||
pass
|
||||
|
||||
|
||||
bp.add_url_rule('/<service>/listener', view_func=UDPListener.as_view('udp_listener', False), methods=['GET'], defaults={'listener_id': None})
|
||||
bp.add_url_rule('/<service>/listener/<int:listener_id>', view_func=UDPListener.as_view('udp_listener_id', False), methods=['GET'])
|
||||
|
|
|
@ -12,6 +12,7 @@ from app.middleware import get_user_params
|
|||
from app.modules.roxywi.class_models import BaseResponse, ErrorResponse
|
||||
from app.views.user.views import UserView, UserGroupView
|
||||
|
||||
|
||||
def register_api_with_group(view, endpoint, url_beg, url_end, pk='user_id', pk_type='int', pk_end='group_id', pk_type_end='int'):
|
||||
view_func = view.as_view(endpoint)
|
||||
bp.add_url_rule(f'/<{pk_type}:{pk}>/{url_end}', view_func=view_func, methods=['GET'])
|
||||
|
@ -27,6 +28,7 @@ def register_api(view, endpoint, url, pk='listener_id', pk_type='int'):
|
|||
register_api(UserView, 'user', '', 'user_id')
|
||||
register_api_with_group(UserGroupView, 'user_group', '', 'groups')
|
||||
|
||||
|
||||
@bp.before_request
|
||||
@jwt_required()
|
||||
def before_request():
|
||||
|
|
|
@ -1448,9 +1448,9 @@ class DefaultsSectionView(HaproxySectionView):
|
|||
def put(self, service: Literal['haproxy'], server_id: Union[int, str], body: HaproxyDefaultsRequest):
|
||||
"""
|
||||
DefaultsSectionView API
|
||||
|
||||
|
||||
This is the DefaultsSectionView API where you can update the defaults configuration of HAProxy.
|
||||
|
||||
|
||||
---
|
||||
tags:
|
||||
- HAProxy defaults section
|
||||
|
|
|
@ -171,7 +171,7 @@ class ServiceView(MethodView):
|
|||
data = ErrorResponse(error=str(e)).model_dump(mode='json')
|
||||
elif service == 'keepalived':
|
||||
cmd = ("sudo /usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}' && sudo systemctl status keepalived |grep -e 'Active'"
|
||||
f"|awk '{{print $2, $9$10$11$12$13}}' && ps ax |grep 'keepalived '|grep -v udp|grep -v grep |wc -l")
|
||||
"|awk '{print $2, $9$10$11$12$13}' && ps ax |grep 'keepalived '|grep -v udp|grep -v grep |wc -l")
|
||||
try:
|
||||
out = server_mod.ssh_command(server.ip, cmd)
|
||||
out1 = out.split()
|
||||
|
@ -562,7 +562,7 @@ class ServiceConfigVersionsView(MethodView):
|
|||
try:
|
||||
server_ip = SupportClass(False).return_server_ip_or_id(server_id)
|
||||
except Exception as e:
|
||||
return roxywi_common.handler_exceptions_for_json_data(e ,'')
|
||||
return roxywi_common.handler_exceptions_for_json_data(e, '')
|
||||
|
||||
config_dir = config_common.get_config_dir(service)
|
||||
file_format = config_common.get_file_format(service)
|
||||
|
@ -613,7 +613,7 @@ class ServiceConfigVersionsView(MethodView):
|
|||
try:
|
||||
server_ip = SupportClass(False).return_server_ip_or_id(server_id)
|
||||
except Exception as e:
|
||||
return roxywi_common.handler_exceptions_for_json_data(e ,'')
|
||||
return roxywi_common.handler_exceptions_for_json_data(e, '')
|
||||
|
||||
for get in body.versions:
|
||||
if file_format in get and server_ip in get:
|
||||
|
|
|
@ -353,12 +353,12 @@ class UDPListener(MethodView):
|
|||
self._reconfigure(listener_id, 'uninstall')
|
||||
roxywi_common.logging(listener_id, f'UDP listener has been deleted {listener_id}', roxywi=1, keep_history=1, login=1, service='UDP listener')
|
||||
except Exception as e:
|
||||
return roxywi_common.handle_json_exceptions(e,f'Cannot create inventory for UDP listener deleting {listener_id}')
|
||||
return roxywi_common.handle_json_exceptions(e, f'Cannot create inventory for UDP listener deleting {listener_id}')
|
||||
try:
|
||||
udp_sql.delete_listener(listener_id)
|
||||
return BaseResponse().model_dump(mode='json'), 204
|
||||
except Exception as e:
|
||||
return roxywi_common.handle_json_exceptions(e,f'Cannot delete UDP listener {listener_id}')
|
||||
return roxywi_common.handle_json_exceptions(e, f'Cannot delete UDP listener {listener_id}')
|
||||
|
||||
@staticmethod
|
||||
def _reconfigure(listener_id, action):
|
||||
|
|
Loading…
Reference in New Issue