Method: Net::SSH::Config.translate

Defined in:
lib/net/ssh/config.rb

.translate(settings) ⇒ Object

Given a hash of OpenSSH configuration options, converts them into a hash of Net::SSH options. Unrecognized options are ignored. The settings hash must have Strings for keys, all downcased, and the returned hash will have Symbols for keys.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/net/ssh/config.rb', line 119

def translate(settings)
  settings.inject({}) do |hash, (key, value)|
    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] ||= []
        hash[:auth_methods] << "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
    when 'identityfile' then
      hash[:keys] = value
    when 'macs' then
      hash[:hmac] = value.split(/,/)
    when 'passwordauthentication'
      if value
        hash[:auth_methods] ||= []
        hash[:auth_methods] << "password"
      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] ||= []
        hash[:auth_methods] << "publickey"
      end
    when 'rekeylimit'
      hash[:rekey_limit] = interpret_size(value)
    when 'user'
      hash[:user] = value
    when 'userknownhostsfile'
      hash[:user_known_hosts_file] = value
    end
    hash
  end
end