backups: Avoid creating duplicate SSH remotes

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Joseph Nuthalapati 2019-05-16 17:28:41 +05:30
parent e618e08fe7
commit fb67c60a84
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -154,7 +154,12 @@ class AddRepositoryForm(forms.Form):
path = cleaned_data.get("repository")
credentials = self.get_credentials()
# Validate remote
# Avoid creation of duplicate ssh remotes
for storage in network_storage.get_storages().values():
if storage['path'] == path:
raise forms.ValidationError(
_('Remote backup repository already exists.'))
user_at_host, dir_path = path.split(':')
username, hostname = user_at_host.split('@')
dir_path = dir_path.replace('~', f'/home/{username}')