2021-10-04 11:31:41 +00:00
|
|
|
from .borg_job import BorgJob, FakeProfile, FakeRepo
|
2020-12-16 02:56:42 +00:00
|
|
|
from vorta.i18n import trans_late
|
2018-11-22 00:43:37 +00:00
|
|
|
from vorta.models import RepoModel
|
2018-11-04 15:37:46 +00:00
|
|
|
|
|
|
|
|
2021-10-04 11:31:41 +00:00
|
|
|
class BorgInfoRepoJob(BorgJob):
|
2018-11-04 15:37:46 +00:00
|
|
|
|
|
|
|
def started_event(self):
|
2019-01-20 03:50:10 +00:00
|
|
|
self.updated.emit(self.tr('Validating existing repo...'))
|
2018-11-04 15:37:46 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def prepare(cls, params):
|
|
|
|
"""
|
|
|
|
Used to validate existing repository when added.
|
|
|
|
"""
|
|
|
|
|
2020-12-16 02:56:42 +00:00
|
|
|
# Build fake profile because we don't have it in the DB yet. Assume unencrypted.
|
2018-11-04 15:37:46 +00:00
|
|
|
profile = FakeProfile(
|
2020-12-16 02:56:42 +00:00
|
|
|
FakeRepo(params['repo_url'], 999, params['extra_borg_arguments'], 'none'),
|
2018-11-17 10:34:38 +00:00
|
|
|
'New Repo',
|
|
|
|
params['ssh_key']
|
2018-11-04 15:37:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ret = super().prepare(profile)
|
|
|
|
if not ret['ok']:
|
|
|
|
return ret
|
|
|
|
else:
|
|
|
|
ret['ok'] = False # Set back to false, so we can do our own checks here.
|
|
|
|
|
|
|
|
cmd = ["borg", "info", "--info", "--json", "--log-json"]
|
|
|
|
cmd.append(profile.repo.url)
|
|
|
|
|
2020-11-18 07:06:10 +00:00
|
|
|
ret['additional_env'] = {
|
|
|
|
'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': "yes",
|
|
|
|
'BORG_RSH': 'ssh -oStrictHostKeyChecking=no'
|
|
|
|
}
|
2020-09-04 11:44:00 +00:00
|
|
|
|
2021-01-18 08:05:25 +00:00
|
|
|
ret['password'] = params['password'] # Empty password is '', which disables prompt
|
|
|
|
if params['password'] != '':
|
2020-12-16 02:56:42 +00:00
|
|
|
# Cannot tell if repo has encryption, assuming based off of password
|
2021-01-18 07:52:07 +00:00
|
|
|
if not cls.keyring.is_unlocked:
|
2020-12-16 02:56:42 +00:00
|
|
|
ret['message'] = trans_late('messages', 'Please unlock your password manager.')
|
|
|
|
return ret
|
|
|
|
|
2018-11-04 15:37:46 +00:00
|
|
|
ret['ok'] = True
|
|
|
|
ret['cmd'] = cmd
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def process_result(self, result):
|
2018-12-14 08:03:26 +00:00
|
|
|
if result['returncode'] == 0:
|
|
|
|
new_repo, _ = RepoModel.get_or_create(
|
|
|
|
url=result['cmd'][-1]
|
|
|
|
)
|
|
|
|
if 'cache' in result['data']:
|
|
|
|
stats = result['data']['cache']['stats']
|
|
|
|
new_repo.total_size = stats['total_size']
|
|
|
|
new_repo.unique_csize = stats['unique_csize']
|
|
|
|
new_repo.unique_size = stats['unique_size']
|
|
|
|
new_repo.total_unique_chunks = stats['total_unique_chunks']
|
|
|
|
if 'encryption' in result['data']:
|
|
|
|
new_repo.encryption = result['data']['encryption']['mode']
|
|
|
|
if new_repo.encryption != 'none':
|
2021-01-18 07:52:07 +00:00
|
|
|
self.keyring.set_password("vorta-repo", new_repo.url, result['params']['password'])
|
2018-12-14 08:03:26 +00:00
|
|
|
|
2019-02-26 11:57:27 +00:00
|
|
|
new_repo.extra_borg_arguments = result['params']['extra_borg_arguments']
|
|
|
|
|
2018-12-14 08:03:26 +00:00
|
|
|
new_repo.save()
|