Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bartender/shared/ssh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict, Optional

from asyncssh import SSHClientConnection, connect
from asyncssh.misc import DefTuple
from pydantic import BaseModel
Expand All @@ -14,7 +16,7 @@ class SshConnectConfig(BaseModel):
hostname: str
port: DefTuple[int] = ()
username: DefTuple[str] = ()
password: DefTuple[str] = ()
password: Optional[str] = None


async def ssh_connect(config: SshConnectConfig) -> SSHClientConnection:
Expand All @@ -26,18 +28,18 @@ async def ssh_connect(config: SshConnectConfig) -> SSHClientConnection:
Returns:
The connection.
"""
conn_vargs = {
conn_vargs: Dict[str, Optional[str]] = {
# disable server host key validation
"known_hosts": None,
}
if config.password:
# Do not use SSH agent when password is supplied.
conn_vargs["agent_path"] = None
conn_vargs["password"] = config.password

return await connect(
host=config.hostname,
port=config.port,
username=config.username,
password=config.password,
**conn_vargs,
)