Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If password is not given is should not be passed to connect #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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,
)