Class: PuppetX::Puppetlabs::AwsIngressRulesParser

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/aws_ingress_rules_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ AwsIngressRulesParser

Returns a new instance of AwsIngressRulesParser.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet_x/puppetlabs/aws_ingress_rules_parser.rb', line 6

def initialize(rules)
  @rules = []
  @rules << rules.reject(&:nil?).collect do |rule|
    # expand port to to_port and from_port
    new_rule = Marshal.load(Marshal.dump(rule))
    if rule.key? 'port'
      value = rule['port']
      new_rule.delete 'port'
      new_rule['from_port'] = value.to_i
      new_rule['to_port'] = value.to_i
    end
    # add default ports if missing
    unless new_rule.key? 'to_port'
      if rule['protocol'] == 'icpm'
        new_rule['from_port']= -1
        new_rule['to_port']= -1
      else
        new_rule['from_port']= 1
        new_rule['to_port']= 65535
      end
    end
    # expand when protocol not specified
    unless rule['protocol']
      ['tcp', 'udp'].each do |proto|
        copy = Marshal.load(Marshal.dump(new_rule))
        copy['protocol'] = proto
        @rules << copy
      end
      new_rule['protocol'] = 'icmp'
      if new_rule.key? 'to_port'
        new_rule['to_port'] = -1
        new_rule['from_port'] = -1
      end
    end
    new_rule
  end
  @rules = @rules.flatten

end

Instance Method Details

#rules_to_create(rules) ⇒ Object



46
47
48
# File 'lib/puppet_x/puppetlabs/aws_ingress_rules_parser.rb', line 46

def rules_to_create(rules)
  stringify_values(@rules) - stringify_values(rules)
end

#rules_to_delete(rules) ⇒ Object



50
51
52
# File 'lib/puppet_x/puppetlabs/aws_ingress_rules_parser.rb', line 50

def rules_to_delete(rules)
  stringify_values(rules) - stringify_values(@rules)
end