Module: Restic::Service::Targets::SSHTarget

Included in:
ResticSFTP, Rsync
Defined in:
lib/restic/service/targets/ssh_target.rb

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/restic/service/targets/ssh_target.rb', line 21

def available?
    ssh = SSHKeys.new
    actual_keys = ssh.query_keys(@host)
    valid?(actual_keys)
end

#initialize(name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/restic/service/targets/ssh_target.rb', line 5

def initialize(name)
    super
    @key_path = nil
    @host = nil
    @username = nil
    @host_keys = []
end

#setup_from_conf(conf, yaml) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/restic/service/targets/ssh_target.rb', line 13

def setup_from_conf(conf, yaml)
    super
    @username  = yaml.fetch('username').to_str
    @host      = yaml.fetch('host').to_str
    @key_path  = conf.conf_keys_path_for(self)
    @host_keys = SSHKeys.load_keys_from_file(@key_path)
end

#valid?(actual_keys) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/restic/service/targets/ssh_target.rb', line 27

def valid?(actual_keys)
    actual_keys.any? { |k| @host_keys.include?(k) }
end

#with_ssh_configObject



31
32
33
34
35
36
37
38
# File 'lib/restic/service/targets/ssh_target.rb', line 31

def with_ssh_config
    ssh = SSHKeys.new
    ssh_config_name = ssh.ssh_setup_config(
        name, @username, @host, @key_path)
    yield(ssh_config_name)
ensure
    ssh.ssh_cleanup_config if ssh_config_name
end