From 49191227fb28098c2648178370e7b216a9c315b4 Mon Sep 17 00:00:00 2001 From: Manu Date: Sat, 17 Nov 2018 18:34:38 +0800 Subject: [PATCH] Pass SSH key if one is selected. Fixes #15 --- src/vorta/assets/UI/mainwindow.ui | 2 +- src/vorta/assets/UI/repotab.ui | 16 ++++++++++++++++ src/vorta/borg/borg_thread.py | 4 +++- src/vorta/borg/create.py | 2 -- src/vorta/borg/info.py | 9 +++++---- src/vorta/borg/init.py | 2 +- src/vorta/views/repo_add.py | 1 - src/vorta/views/repo_tab.py | 2 +- tests/test_repo.py | 2 +- 9 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/vorta/assets/UI/mainwindow.ui b/src/vorta/assets/UI/mainwindow.ui index 69d05f40..5fc3d0a1 100644 --- a/src/vorta/assets/UI/mainwindow.ui +++ b/src/vorta/assets/UI/mainwindow.ui @@ -135,7 +135,7 @@ - 3 + 0 false diff --git a/src/vorta/assets/UI/repotab.ui b/src/vorta/assets/UI/repotab.ui index 70efa8ea..b51973de 100644 --- a/src/vorta/assets/UI/repotab.ui +++ b/src/vorta/assets/UI/repotab.ui @@ -65,6 +65,14 @@ + + + 12 + + + + margin-bottom: 10 + <html><head/><body><p>SSH account with Borg installed server-side. Or try <a href="https://www.borgbase.com?utm_source=vorta"><span style=" text-decoration: underline; color:#0000ff;">BorgBase</span></a>. 100GB free during Beta.</p></body></html> @@ -92,6 +100,14 @@ + + + 12 + + + + margin-bottom: 10 + To access repository securely. Keep default to use all your existing keys. Or create new key. diff --git a/src/vorta/borg/borg_thread.py b/src/vorta/borg/borg_thread.py index a3acbe1b..4261e230 100644 --- a/src/vorta/borg/borg_thread.py +++ b/src/vorta/borg/borg_thread.py @@ -44,7 +44,7 @@ class BorgThread(QtCore.QThread, BackupProfileMixin): env['BORG_PASSPHRASE'] = params['password'] env['BORG_RSH'] = 'ssh -oStrictHostKeyChecking=no' - if params.get('ssh_key') and params['ssh_key']: + if params.get('ssh_key') and params['ssh_key'] is not None: env['BORG_RSH'] += f' -i ~/.ssh/{params["ssh_key"]}' self.env = env @@ -89,6 +89,8 @@ class BorgThread(QtCore.QThread, BackupProfileMixin): ret['message'] = 'Add a remote backup repository first.' return ret + ret['ssh_key'] = profile.ssh_key + ret['repo_id'] = profile.repo.id ret['repo_url'] = profile.repo.url ret['profile_name'] = profile.name ret['password'] = keyring.get_password("vorta-repo", profile.repo.url) # None if no password. diff --git a/src/vorta/borg/create.py b/src/vorta/borg/create.py index d73f7e9c..0fee66a3 100644 --- a/src/vorta/borg/create.py +++ b/src/vorta/borg/create.py @@ -101,7 +101,5 @@ class BorgCreateThread(BorgThread): ret['message'] = 'Starting backup..' ret['ok'] = True ret['cmd'] = cmd - ret['repo_id'] = profile.repo.id - ret['ssh_key'] = None # TODO: implement return ret diff --git a/src/vorta/borg/info.py b/src/vorta/borg/info.py index 2b34042a..9d47f487 100644 --- a/src/vorta/borg/info.py +++ b/src/vorta/borg/info.py @@ -3,8 +3,8 @@ from .borg_thread import BorgThread from vorta.models import SnapshotModel, RepoModel from vorta.utils import keyring -FakeRepo = namedtuple('Repo', ['url']) # TODO: implement passing SSH key. -FakeProfile = namedtuple('FakeProfile', ['repo', 'name']) +FakeRepo = namedtuple('Repo', ['url', 'id']) +FakeProfile = namedtuple('FakeProfile', ['repo', 'name', 'ssh_key']) class BorgInfoThread(BorgThread): @@ -20,8 +20,9 @@ class BorgInfoThread(BorgThread): # Build fake profile because we don't have it in the DB yet. profile = FakeProfile( - FakeRepo(params['repo_url']), - 'New Repo' + FakeRepo(params['repo_url'], 999), + 'New Repo', + params['ssh_key'] ) ret = super().prepare(profile) diff --git a/src/vorta/borg/init.py b/src/vorta/borg/init.py index 7466657d..7f702bcd 100644 --- a/src/vorta/borg/init.py +++ b/src/vorta/borg/init.py @@ -13,7 +13,7 @@ class BorgInitThread(BorgThread): # Build fake profile because we don't have it in the DB yet. profile = FakeProfile( - FakeRepo(params['repo_url']), 'Init Repo' + FakeRepo(params['repo_url'], 999), 'Init Repo', params['ssh_key'] ) ret = super().prepare(profile) diff --git a/src/vorta/views/repo_add.py b/src/vorta/views/repo_add.py index c7b837c3..4ef3565b 100644 --- a/src/vorta/views/repo_add.py +++ b/src/vorta/views/repo_add.py @@ -68,7 +68,6 @@ class AddRepoWindow(AddRepoBase, AddRepoUI): def validate(self): """Pre-flight check for valid input and borg binary.""" - # TODO: valid repo is xx.xx:xx. add rex if len(self.values['repo_url']) < 5 or ':' not in self.values['repo_url']: self._set_status('Please enter a valid repo URL including hostname and path.') return False diff --git a/src/vorta/views/repo_tab.py b/src/vorta/views/repo_tab.py index e3e14cf0..aa537c12 100644 --- a/src/vorta/views/repo_tab.py +++ b/src/vorta/views/repo_tab.py @@ -74,7 +74,7 @@ class RepoTab(RepoBase, RepoUI, BackupProfileMixin): self.sshComboBox.addItem('Automatically choose SSH Key (default)', None) self.sshComboBox.addItem('Create New Key', 'new') for key in keys: - self.sshComboBox.addItem(f'{key["filename"]} ({key["format"]}:{key["fingerprint"]})', key['filename']) + self.sshComboBox.addItem(f'{key["filename"]} ({key["format"]})', key['filename']) def ssh_select_action(self, index): if index == 1: diff --git a/tests/test_repo.py b/tests/test_repo.py index 71f6ff9a..5d8b7684 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -6,7 +6,7 @@ from vorta.views.repo_add import AddRepoWindow from vorta.models import EventLogModel, RepoModel, SnapshotModel -def test_create_error(app, qtbot): +def test_create_fail(app, qtbot): main = app.main_window qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton) assert main.createProgressText.text() == 'Add a remote backup repository first.'