Files
cursor_ai/modules/protocols.py

53 lines
1.5 KiB
Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Протоколы и интерфейсы для модулей SSH Client.
Обеспечивают единый контракт для SSH-операций и операционных модулей.
"""
from typing import List, Protocol, runtime_checkable
@runtime_checkable
class SSHProtocol(Protocol):
"""
Протокол SSH-клиента: connect, cmd, close.
Реализуется SSHBase и SSHClient.
"""
def connect(self) -> None:
"""Подключение к удалённому серверу."""
...
def cmd(
self,
command: str,
sleep: float = 0.1,
out_to_print: bool = False,
suppress_warnings: bool = False,
) -> List[str]:
"""
Выполнение команды на удалённом сервере.
Returns:
[stdout, stderr]
"""
...
def close(self) -> None:
"""Закрытие соединения."""
...
class SSHOperationsBase:
"""
Базовый класс для операционных модулей (PostgreSQL, 1C, ZFS и т.д.).
Ожидает ssh_client, реализующий SSHProtocol.
"""
def __init__(self, ssh_client: SSHProtocol) -> None:
"""
Args:
ssh_client: Экземпляр, реализующий SSHProtocol (SSHBase, SSHClient).
"""
self.ssh: SSHProtocol = ssh_client