Skip to content

Commit

Permalink
If password is not given is should not be passed to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
sverhoeven committed Oct 25, 2024
1 parent fc9c1de commit 477394e
Showing 1 changed file with 5 additions and 3 deletions.
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,
)

0 comments on commit 477394e

Please sign in to comment.