This commit is contained in:
Mateusz Gruszczyński
2026-04-15 10:33:26 +02:00
parent 14f83cd549
commit 9ddb203ec0
16 changed files with 348 additions and 257 deletions

View File

@@ -28,8 +28,6 @@ def serialize_router(router: Router, global_settings) -> RouterResponse:
effective_username = router_user
uses_global_switchos_credentials = False
has_effective_password = bool(router_password)
uses_global_ssh_key = False
has_effective_ssh_key = False
if router.device_type == 'switchos':
effective_username = router_user or default_swos_user
@@ -37,15 +35,11 @@ def serialize_router(router: Router, global_settings) -> RouterResponse:
(not router_user and default_swos_user) or (not router_password and default_swos_password)
)
has_effective_password = bool(router_password or default_swos_password)
else:
uses_password_auth = bool(router_password)
uses_global_ssh_key = bool(has_global_key and not has_router_key and not uses_password_auth)
has_effective_ssh_key = bool(has_router_key or uses_global_ssh_key)
payload = RouterResponse.model_validate(router, from_attributes=True).model_dump()
payload['effective_username'] = effective_username
payload['uses_global_ssh_key'] = uses_global_ssh_key
payload['has_effective_ssh_key'] = has_effective_ssh_key
payload['uses_global_ssh_key'] = router.device_type == 'routeros' and has_global_key and not has_router_key
payload['has_effective_ssh_key'] = router.device_type == 'routeros' and (has_router_key or has_global_key)
payload['uses_global_switchos_credentials'] = uses_global_switchos_credentials
payload['has_effective_password'] = has_effective_password
payload['supports_export'] = router.device_type == 'routeros'