lib/fulmar/infrastructure/service/ssh_config_service.rb in fulmar-1.10.1 vs lib/fulmar/infrastructure/service/ssh_config_service.rb in fulmar-2.0.0

- old
+ new

@@ -5,30 +5,17 @@ module Service # Adds entries to the ssh config and checks for existing ones class SSHConfigService CONFIG_FILE = "#{ENV['HOME']}/.ssh/config" KNOWN_HOST_FILE = "#{ENV['HOME']}/.ssh/known_hosts" - # @todo: Get rid of this layer (Version 2?) - CONFIG_MAP = { - hostname: 'Hostname', - port: 'Port', - user: 'User', - proxycommand: 'ProxyCommand', - checkhostip: 'CheckHostIP', - stricthostkeychecking: 'StrictHostKeyChecking', - identityfile: 'IdentityFile', - userknownhostfile: 'UserKnownHostsFile', - loglevel: 'LogLevel', - forwardagent: 'ForwardAgent' - } def initialize(config) @config = config end def add_hosts - @config.configuration[:hosts].values.each do |data| + @config.hosts.values.each do |data| unless config_valid?(data) puts "Skipping #{data[:hostname]}, config not sufficient." if @config[:debug] next end if host_exists?(data[:hostname]) @@ -66,20 +53,20 @@ # Adds a host to the ssh config file def add_host(hostname, ssh_config = {}) puts "Adding host #{hostname}..." if @config[:debug] config_file = File.open(CONFIG_FILE, 'a') - unless ssh_config[:identityfile].blank? or ssh_config[:identityfile][0, 1] == '/' - ssh_config[:identityfile] = @config.base_path + '/' + ssh_config[:identityfile] + unless ssh_config[:IdentityFile].blank? or ssh_config[:IdentityFile][0, 1] == '/' + ssh_config[:IdentityFile] = @config.base_path + '/' + ssh_config[:IdentityFile] end config_file.puts "\n" # Add some space between this and the second last entry - config_file.puts "# Automatically generated by fulmar for project #{@config.project.description}" + config_file.puts "# Automatically generated by fulmar for project '#{@config.project.description}'" config_file.puts "Host #{hostname}" - CONFIG_MAP.keys.each do |key| - unless ssh_config[key].blank? - config_file.puts " #{CONFIG_MAP[key]} \"#{ssh_config[key].to_s.gsub('"', '\\"')}\"" - end + ssh_config.keys.each do |key| + value = ssh_config[key].to_s + value = "\"#{value.gsub('"', '\\"')}\"" if value.include?(' ') + config_file.puts " #{key} #{value}" end config_file.close end