Skip to content

Commit

Permalink
Read kano host config from ssh config file
Browse files Browse the repository at this point in the history
Paramiko doesn't automatically reads from the ssh config file, we need
to do it explicitly.

Closes #1
  • Loading branch information
mandre committed Feb 2, 2020
1 parent 58d299f commit 8ec82bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
23 changes: 22 additions & 1 deletion pull_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,28 @@ def copy_kano_overworld_file(project, podir, lang):
# authentication setup
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('kano')

ssh_config = paramiko.SSHConfig()
user_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)

if 'kano' not in ssh_config.get_hostnames():
print("The \"kano\" host was not found in $HOME/.ssh/config.\n")
print("Check how to set it up SSH at:")
print("https://github.com/mandre/kano-i18n-sync#setup")
exit()

cfg = {}
host_config = ssh_config.lookup('kano')
for k in ('hostname', 'username', 'port'):
if k in host_config:
cfg[k] = host_config[k]
if 'proxycommand' in host_config:
cfg['sock'] = paramiko.ProxyCommand(host_config['proxycommand'])

ssh.connect(**cfg)

scp = ssh.open_sftp()

Expand Down
23 changes: 22 additions & 1 deletion sync_pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,28 @@ def upload_pot_files(project, potdir):
# authentication setup
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('kano')

ssh_config = paramiko.SSHConfig()
user_config_file = os.path.expanduser("~/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)

if 'kano' not in ssh_config.get_hostnames():
print("The \"kano\" host was not found in $HOME/.ssh/config.\n")
print("Check how to set it up SSH at:")
print("https://github.com/mandre/kano-i18n-sync#setup")
exit()

cfg = {}
host_config = ssh_config.lookup('kano')
for k in ('hostname', 'username', 'port'):
if k in host_config:
cfg[k] = host_config[k]
if 'proxycommand' in host_config:
cfg['sock'] = paramiko.ProxyCommand(host_config['proxycommand'])

ssh.connect(**cfg)

scp = ssh.open_sftp()

Expand Down

0 comments on commit 8ec82bd

Please sign in to comment.