Skip to content

Commit

Permalink
pxssh.login require either username or ssh_config
Browse files Browse the repository at this point in the history
If pxssh.login is called with an ssh_config then do not require username since it can be supplied via the config and some programs do not want to manage the username at all since it would require parsing the ssh config.

This commit removes the independent username parameter when formatting cmd and instead appends the flag and the username to ssh_options if a username is provided.

If neither username nor ssh_config is provided raise a TypeError in line with the error raised natively if username was not provided as a required positional argument.
  • Loading branch information
tgbugs committed Mar 21, 2019
1 parent 03168dd commit 8305dae
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pexpect/pxssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def sync_original_prompt (self, sync_multiplier=1.0):
### TODO: This is getting messy and I'm pretty sure this isn't perfect.
### TODO: I need to draw a flow chart for this.
### TODO: Unit tests for SSH tunnels, remote SSH command exec, disabling original prompt sync
def login (self, server, username, password='', terminal_type='ansi',
def login (self, server, username=None, password='', terminal_type='ansi',
original_prompt=r"[#$]", login_timeout=10, port=None,
auto_prompt_reset=True, ssh_key=None, quiet=True,
sync_multiplier=1, check_local_ip=True,
Expand Down Expand Up @@ -354,7 +354,13 @@ def login (self, server, username, password='', terminal_type='ansi',
if spawn_local_ssh==False:
tunnel = quote(str(tunnel))
ssh_options = ssh_options + ' -' + cmd_type + ' ' + str(tunnel)
cmd = "ssh %s -l %s %s" % (ssh_options, username, server)

if username is not None:
ssh_options = ssh_options + ' -l ' + username
elif ssh_config is None:
raise TypeError('login() needs either a username or an ssh_config')

cmd = "ssh %s %s" % (ssh_options, server)
if self.debug_command_string:
return(cmd)

Expand Down

0 comments on commit 8305dae

Please sign in to comment.