This commit is contained in:
Mateusz Gruszczyński
2026-04-15 09:22:15 +02:00
parent b02a2f3a8e
commit 14f83cd549
10 changed files with 235 additions and 63 deletions

View File

@@ -28,6 +28,8 @@ 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
@@ -35,11 +37,15 @@ 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'] = 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_ssh_key'] = uses_global_ssh_key
payload['has_effective_ssh_key'] = has_effective_ssh_key
payload['uses_global_switchos_credentials'] = uses_global_switchos_credentials
payload['has_effective_password'] = has_effective_password
payload['supports_export'] = router.device_type == 'routeros'