lib/kakine/resource/yaml.rb in kakine-0.6.2 vs lib/kakine/resource/yaml.rb in kakine-0.6.4

- old
+ new

@@ -9,11 +9,11 @@ def load_file(filename) data = yaml(filename).reject {|k, _| k.start_with?('_') && k.end_with?('_') } validate_file_input(data) data.each do |name, params| - params['rules'] = perform_expansion(params['rules']) if params['rules'] + params['rules'] = perform_desugar(perform_expansion(params['rules'])) if params['rules'] end end def yaml(filename) YAML.load_file(filename).to_hash @@ -96,9 +96,23 @@ %w(remote_ip port protocol).each do |key| rules = expand_rules(rules, key) end rules + end + + def perform_desugar(rules) + rules.map do |rule| + if rule['port'].is_a?(String) && rule['port'] =~ /\A(?<min>\d+)-(?<max>\d+)\z/ + rule.dup.tap do |rule| + rule.delete('port') + rule['port_range_min'] = $~[:min].to_i + rule['port_range_max'] = $~[:max].to_i + end + else + rule + end + end end end end end end