mirror of https://github.com/Aidaho12/haproxy-wi
v8.2: Refactor ServiceInstall API validation.
Replaced `ServiceInstallFromApi` with `ServiceInstall` for API validation in installation views and function parameters. Simplified the `ServiceInstall` class by removing duplicate attributes and making list and dict attributes optional.pull/399/head
parent
7fdc977bc2
commit
ddaa3bf2dd
|
@ -221,21 +221,12 @@ class ServerInstall(BaseModel):
|
||||||
|
|
||||||
class ServiceInstall(BaseModel):
|
class ServiceInstall(BaseModel):
|
||||||
cluster_id: Optional[int] = None
|
cluster_id: Optional[int] = None
|
||||||
servers: List[ServerInstall]
|
|
||||||
services: Dict[str, HAClusterService]
|
|
||||||
checker: Optional[bool] = 0
|
|
||||||
metrics: Optional[bool] = 0
|
|
||||||
auto_start: Optional[bool] = 0
|
|
||||||
syn_flood: Optional[bool] = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceInstallFromApi(BaseModel):
|
|
||||||
checker: Optional[bool] = 0
|
|
||||||
metrics: Optional[bool] = 0
|
|
||||||
auto_start: Optional[bool] = 0
|
|
||||||
syn_flood: Optional[bool] = 0
|
|
||||||
servers: Optional[List[ServerInstall]] = None
|
servers: Optional[List[ServerInstall]] = None
|
||||||
services: Optional[Dict[str, HAClusterService]] = None
|
services: Optional[Dict[str, HAClusterService]] = None
|
||||||
|
checker: Optional[bool] = 0
|
||||||
|
metrics: Optional[bool] = 0
|
||||||
|
auto_start: Optional[bool] = 0
|
||||||
|
syn_flood: Optional[bool] = 0
|
||||||
docker: Optional[bool] = 0
|
docker: Optional[bool] = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import app.modules.server.server as server_mod
|
||||||
import app.modules.roxywi.common as roxywi_common
|
import app.modules.roxywi.common as roxywi_common
|
||||||
from app.modules.server.ssh import return_ssh_keys_path
|
from app.modules.server.ssh import return_ssh_keys_path
|
||||||
from app.modules.roxywi.class_models import ServiceInstall, HAClusterRequest, HaproxyGlobalRequest, \
|
from app.modules.roxywi.class_models import ServiceInstall, HAClusterRequest, HaproxyGlobalRequest, \
|
||||||
HaproxyDefaultsRequest, HaproxyConfigRequest, ServiceInstallFromApi
|
HaproxyDefaultsRequest, HaproxyConfigRequest
|
||||||
|
|
||||||
|
|
||||||
def generate_udp_inv(listener_id: int, action: str) -> object:
|
def generate_udp_inv(listener_id: int, action: str) -> object:
|
||||||
|
@ -427,7 +427,7 @@ def _create_default_config_in_db(server_id: int) -> None:
|
||||||
add_sql.insert_new_section(server_id, 'listen', 'stats', stats_config)
|
add_sql.insert_new_section(server_id, 'listen', 'stats', stats_config)
|
||||||
|
|
||||||
|
|
||||||
def install_service(service: str, json_data: Union[str, ServiceInstall, HAClusterRequest, ServiceInstallFromApi], cluster_id: int = None) -> dict:
|
def install_service(service: str, json_data: Union[str, ServiceInstall, HAClusterRequest], cluster_id: int = None) -> dict:
|
||||||
generate_functions = {
|
generate_functions = {
|
||||||
'haproxy': generate_haproxy_inv,
|
'haproxy': generate_haproxy_inv,
|
||||||
'nginx': generate_service_inv,
|
'nginx': generate_service_inv,
|
||||||
|
|
|
@ -662,7 +662,7 @@ $( function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#" + section_type + "_blacklist_checkbox").click(function () {
|
$("#" + section_type + "_blacklist_checkbox").click(function () {
|
||||||
if ($('#frontend_blacklist_checkbox').is(':checked')) {
|
if ($("#" + section_type + "_blacklist_checkbox").is(':checked')) {
|
||||||
$("#" + section_type + "_blacklist-hide").show("fast");
|
$("#" + section_type + "_blacklist-hide").show("fast");
|
||||||
$("#" + section_type + "_blacklist-hide-input").attr('required', true);
|
$("#" + section_type + "_blacklist-hide-input").attr('required', true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -672,7 +672,7 @@ $( function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#" + section_type + "_whitelist_checkbox").click(function () {
|
$("#" + section_type + "_whitelist_checkbox").click(function () {
|
||||||
if ($('#frontend_whitelist_checkbox').is(':checked')) {
|
if ($("#" + section_type + "_whitelist_checkbox").is(':checked')) {
|
||||||
$("#" + section_type + "_whitelist-hide").show("fast");
|
$("#" + section_type + "_whitelist-hide").show("fast");
|
||||||
$("#" + section_type + "_whitelist-hide-input").attr('required', true);
|
$("#" + section_type + "_whitelist-hide-input").attr('required', true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import app.modules.db.service as service_sql
|
||||||
import app.modules.service.installation as service_mod
|
import app.modules.service.installation as service_mod
|
||||||
from app.middleware import get_user_params, check_services, page_for_admin, check_group
|
from app.middleware import get_user_params, check_services, page_for_admin, check_group
|
||||||
from app.modules.common.common_classes import SupportClass
|
from app.modules.common.common_classes import SupportClass
|
||||||
from app.modules.roxywi.class_models import ServiceInstallFromApi, IdStrResponse, BaseResponse, ServerInstall, HAClusterService
|
from app.modules.roxywi.class_models import ServiceInstall, IdStrResponse, BaseResponse, ServerInstall, HAClusterService
|
||||||
from app.views.service.views import ServiceView
|
from app.views.service.views import ServiceView
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,8 +81,8 @@ class InstallView(MethodView):
|
||||||
methods = ['POST', 'PUT', 'DELETE']
|
methods = ['POST', 'PUT', 'DELETE']
|
||||||
decorators = [jwt_required(), get_user_params(), check_services, page_for_admin(level=3), check_group()]
|
decorators = [jwt_required(), get_user_params(), check_services, page_for_admin(level=3), check_group()]
|
||||||
|
|
||||||
@validate(body=ServiceInstallFromApi)
|
@validate(body=ServiceInstall)
|
||||||
def post(self, service: Literal['haproxy', 'nginx', 'apache', 'keepalived'], server_id: Union[int, str, None], body: ServiceInstallFromApi):
|
def post(self, service: Literal['haproxy', 'nginx', 'apache', 'keepalived'], server_id: Union[int, str, None], body: ServiceInstall):
|
||||||
"""
|
"""
|
||||||
Install a specific service.
|
Install a specific service.
|
||||||
---
|
---
|
||||||
|
@ -147,8 +147,8 @@ class InstallView(MethodView):
|
||||||
return output
|
return output
|
||||||
return IdStrResponse(id=f'{server_id}-{service}').model_dump(mode='json'), 201
|
return IdStrResponse(id=f'{server_id}-{service}').model_dump(mode='json'), 201
|
||||||
|
|
||||||
@validate(body=ServiceInstallFromApi)
|
@validate(body=ServiceInstall)
|
||||||
def put(self, service: Literal['haproxy', 'nginx', 'apache', 'keepalived'], server_id: Union[int, str, None], body: ServiceInstallFromApi):
|
def put(self, service: Literal['haproxy', 'nginx', 'apache', 'keepalived'], server_id: Union[int, str, None], body: ServiceInstall):
|
||||||
"""
|
"""
|
||||||
Update service Tools settings.
|
Update service Tools settings.
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue