mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
backups: Read file path of known_hosts directly from plinth.config
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
8 files changed
+10
-8
No files matched your search
@@ -149,7 +149,7 @@ def is_ssh_hostkey_verified(hostname):
|
||||
"""Check whether SSH Hostkey has already been verified.
|
||||
hostname: Domain name or IP address of the host
|
||||
"""
|
||||
known_hosts_path = os.path.join(cfg.data_dir, '.ssh', 'known_hosts')
|
||||
known_hosts_path = cfg.known_hosts
|
||||
if not os.path.exists(known_hosts_path):
|
||||
return False
|
||||
|
||||
|
||||
@@ -330,10 +330,9 @@ class SshBorgRepository(BorgRepository):
|
||||
def mount(self):
|
||||
if self.is_mounted:
|
||||
return
|
||||
known_hosts_path = os.path.join(cfg.data_dir, '.ssh', 'known_hosts')
|
||||
arguments = [
|
||||
'mount', '--mountpoint', self.mountpoint, '--path', self._path,
|
||||
'--user-known-hosts-file', known_hosts_path
|
||||
'--user-known-hosts-file', cfg.known_hosts
|
||||
]
|
||||
arguments, kwargs = self._append_sshfs_arguments(
|
||||
arguments, self.credentials)
|
||||
|
||||
@@ -327,7 +327,7 @@ class VerifySshHostkeyView(SuccessMessageMixin, FormView):
|
||||
@staticmethod
|
||||
def _add_ssh_hostkey(hostname, key_type):
|
||||
"""Add the given SSH key to known_hosts."""
|
||||
known_hosts_path = os.path.join(cfg.data_dir, '.ssh', 'known_hosts')
|
||||
known_hosts_path = cfg.known_hosts
|
||||
if not os.path.exists(known_hosts_path):
|
||||
os.makedirs(known_hosts_path.rsplit('/', maxsplit=1)[0])
|
||||
open(known_hosts_path, 'w').close()
|
||||
@@ -440,9 +440,7 @@ def _validate_remote_repository(path, credentials, uuid=None):
|
||||
def _ssh_connection(hostname, username, password):
|
||||
"""Context manager to create and close an SSH connection."""
|
||||
ssh_client = paramiko.SSHClient()
|
||||
|
||||
known_hosts_path = os.path.join(cfg.data_dir, '.ssh', 'known_hosts')
|
||||
ssh_client.load_host_keys(known_hosts_path)
|
||||
ssh_client.load_host_keys(cfg.known_hosts)
|
||||
|
||||
try:
|
||||
ssh_client.connect(hostname, username=username, password=password)
|
||||
|
||||
Reference in new issue
Block a user