Skip to content

Commit

Permalink
Add default session class if backend couldn't be imported.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapaioa committed Apr 8, 2024
1 parent dfe6dff commit e7b85a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion broker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
from broker import helpers
from broker.exceptions import NotImplementedError
from broker.settings import settings
from broker.ssh_session import BaseSession

SSH_BACKENDS = ("ssh2-python", "ssh2-python312", "ansible-pylibssh", "hussh")
SSH_BACKEND = settings.SSH_BACKEND

logger.info(f"{SSH_BACKEND=}")

try:
if SSH_BACKEND == "ansible-pylibssh":
from broker.ssh_session_pylibssh import InteractiveShell, Session
elif SSH_BACKEND == "hussh":
from broker.ssh_session_hussh import Session
elif SSH_BACKEND in ("ssh2-python", "ssh2-python312"):
from broker.ssh_session_ssh2 import InteractiveShell, Session # noqa: F401
from broker.ssh_session_ssh2 import InteractiveShell, Session # noqa: F401
else:
from broker.ssh_session import BaseSession as Session
logger.warning(
f"SSH backend {SSH_BACKEND!r} not supported.\n"
"Supported ssh backends:\n"
f"{SSH_BACKENDS}"
)
except ImportError:
from broker.ssh_session import BaseSession as Session
logger.warning(
f"{SSH_BACKEND} is not installed.\n"
"ssh actions will not work.\n"
Expand Down
4 changes: 4 additions & 0 deletions broker/ssh_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ def _create_connect_socket(host, port, timeout, ipv6=False, ipv4_fallback=True,
else:
sock.connect((host, port))
return sock, ipv6


class BaseSession:
"""Default wrapper around ssh backend's auth/connection system."""

0 comments on commit e7b85a7

Please sign in to comment.