Sha256: 4bc49a50d779c4bc26547c0421837da8e19ecf23bd745c5596a27155f381f46e
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
module Sconb module SSHConfig class << self def load(path, regexp_str = '.*', options = []) @path = path @regexp = Regexp.new(regexp_str) @options = options file = File.expand_path(@path) @configs = {} return @configs unless File.readable?(file) @allconfig = Net::SSH::Config.load_with_key(@path, '*', @options) @configs['*'] = @allconfig unless @allconfig.size <= 1 IO.foreach(file) do |line| parse(line) end @configs end private def parse(line) return if line =~ /^\s*(?:#.*)?$/ if line =~ /^\s*(\S+)\s*=(.*)$/ key = Regexp.last_match[1] value = Regexp.last_match[2] else key, value = line.strip.split(/\s+/, 2) end return if value.nil? # Host if key.downcase == 'host' negative_hosts, positive_hosts = value.to_s.split(/\s+/).partition { |h| h.start_with?('!') } positive_hosts.each do |host| next if host == '*' next unless host.match @regexp config = Net::SSH::Config.load_with_key(@path, host, @options) @allconfig.each do |k, _v| next unless config.key? k config.delete k if config[k] == @allconfig[k] end @configs[host] = config end end # Match if key.downcase == 'match' match_key = key + ' ' + value return unless match_key.match @regexp @configs[match_key] = Net::SSH::Config.load_with_key(@path, value, @options) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sconb-1.1.1 | lib/sconb/ssh_config.rb |