def translate(settings)
settings.inject({}) do |hash, (key, value)|
hash[:auth_methods] ||= settings[:auth_methods] || default_auth_methods.clone
case key
when 'bindaddress' then
hash[:bind_address] = value
when 'ciphers' then
hash[:encryption] = value.split(/,/)
when 'compression' then
hash[:compression] = value
when 'compressionlevel' then
hash[:compression_level] = value
when 'connecttimeout' then
hash[:timeout] = value
when 'forwardagent' then
hash[:forward_agent] = value
when 'identitiesonly' then
hash[:keys_only] = value
when 'globalknownhostsfile'
hash[:global_known_hosts_file] = value
when 'hostbasedauthentication' then
if value
(hash[:auth_methods] << "hostbased").uniq!
else
hash[:auth_methods].delete("hostbased")
end
when 'hostkeyalgorithms' then
hash[:host_key] = value.split(/,/)
when 'hostkeyalias' then
hash[:host_key_alias] = value
when 'hostname' then
hash[:host_name] = value.gsub(/%h/, settings['host'])
when 'identityfile' then
hash[:keys] = value
when 'macs' then
hash[:hmac] = value.split(/,/)
when 'passwordauthentication'
if value
(hash[:auth_methods] << 'password').uniq!
else
hash[:auth_methods].delete('password')
end
when 'challengeresponseauthentication'
if value
(hash[:auth_methods] << 'keyboard-interactive').uniq!
else
hash[:auth_methods].delete('keyboard-interactive')
end
when 'port'
hash[:port] = value
when 'preferredauthentications'
hash[:auth_methods] = value.split(/,/)
when 'proxycommand'
if value and !(value =~ /^none$/)
require 'net/ssh/proxy/command'
hash[:proxy] = Net::SSH::Proxy::Command.new(value)
end
when 'pubkeyauthentication'
if value
(hash[:auth_methods] << 'publickey').uniq!
else
hash[:auth_methods].delete('publickey')
end
when 'rekeylimit'
hash[:rekey_limit] = interpret_size(value)
when 'user'
hash[:user] = value
when 'userknownhostsfile'
hash[:user_known_hosts_file] = value
when 'sendenv'
multi_send_env = value.to_s.split(/\s+/)
hash[:send_env] = multi_send_env.map { |e| Regexp.new pattern2regex(e).source, false }
end
hash
end
end