Class: Cumulus::VPC::AclEntryConfig
- Inherits:
-
Object
- Object
- Cumulus::VPC::AclEntryConfig
- Defined in:
- lib/vpc/models/AclEntryConfig.rb
Overview
Public: An object representing configuration for a VPC Network ACL Entry
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#cidr_block ⇒ Object
readonly
Returns the value of attribute cidr_block.
-
#icmp_code ⇒ Object
readonly
Returns the value of attribute icmp_code.
-
#icmp_type ⇒ Object
readonly
Returns the value of attribute icmp_type.
-
#ports ⇒ Object
readonly
Returns the value of attribute ports.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#expand_ports ⇒ Object
Public: expands the ports string into a from and to port.
-
#initialize(json = nil) ⇒ AclEntryConfig
constructor
Public: Constructor.
- #populate!(aws) ⇒ Object
-
#pretty_string ⇒ Object
Public: creates a string representation of the entry for printing in the console.
- #to_hash ⇒ Object
Constructor Details
#initialize(json = nil) ⇒ AclEntryConfig
Public: Constructor
json - a hash containing the JSON configuration for the entry
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 21 def initialize(json = nil) if !json.nil? @rule = json["rule"] @protocol = json["protocol"] @action = json["action"] @cidr_block = json["cidr-block"] @ports = json["ports"] @icmp_type = json["icmp-type"] @icmp_code = json["icmp-code"] end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
12 13 14 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 12 def action @action end |
#cidr_block ⇒ Object (readonly)
Returns the value of attribute cidr_block.
13 14 15 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 13 def cidr_block @cidr_block end |
#icmp_code ⇒ Object (readonly)
Returns the value of attribute icmp_code.
16 17 18 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 16 def icmp_code @icmp_code end |
#icmp_type ⇒ Object (readonly)
Returns the value of attribute icmp_type.
15 16 17 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 15 def icmp_type @icmp_type end |
#ports ⇒ Object (readonly)
Returns the value of attribute ports.
14 15 16 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 14 def ports @ports end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
11 12 13 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 11 def protocol @protocol end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
10 11 12 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 10 def rule @rule end |
Instance Method Details
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource populated in an AclEntryConfig
Returns an array of the AclEntryDiffs that were found
115 116 117 118 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 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 115 def diff(aws) diffs = [] if @protocol.downcase != aws.protocol.downcase diffs << AclEntryDiff.new(AclEntryChange::PROTOCOL, aws.protocol, @protocol) end if @action != aws.action diffs << AclEntryDiff.new(AclEntryChange::ACTION, aws.action, @action) end if @cidr_block != aws.cidr_block diffs << AclEntryDiff.new(AclEntryChange::CIDR, aws.cidr_block, @cidr_block) end local_from_port, local_to_port = aws_from_port, aws_to_port = aws. if local_from_port != aws_from_port or local_to_port != aws_to_port diffs << AclEntryDiff.new(AclEntryChange::PORTS, aws.ports, @ports) end if @icmp_type != aws.icmp_type diffs << AclEntryDiff.new(AclEntryChange::ICMP_TYPE, aws.icmp_type, @icmp_type) end if @icmp_code != aws.icmp_code diffs << AclEntryDiff.new(AclEntryChange::ICMP_CODE, aws.icmp_code, @icmp_code) end diffs end |
#expand_ports ⇒ Object
Public: expands the ports string into a from and to port
Returns the from port and to port as Integer
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 78 def # Get the local port values as integers local_from_port = nil local_to_port = nil if @ports.is_a? String parts = @ports.split("-").map(&:strip) local_from_port = parts[0].to_i local_to_port = parts[1].to_i elsif @ports.is_a? Integer local_from_port = port local_to_port = port end return local_from_port, local_to_port end |
#populate!(aws) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 45 def populate!(aws) @rule = aws.rule_number @protocol = EC2::IPProtocolMapping.keyword(aws.protocol) @action = aws.rule_action @cidr_block = aws.cidr_block aws_from_port = aws.port_range.from if aws.port_range aws_to_port = aws.port_range.to if aws.port_range if aws_from_port if aws_from_port == aws_to_port @ports = aws_from_port.to_i else @ports = "#{aws_from_port}-#{aws_to_port}" end end aws_icmp_type = aws.icmp_type_code.type if aws.icmp_type_code if aws_icmp_type @icmp_type = aws_icmp_type end aws_icmp_code = aws.icmp_type_code.code if aws.icmp_type_code if aws_icmp_code @icmp_code = aws_icmp_code end self end |
#pretty_string ⇒ Object
Public: creates a string representation of the entry for printing in the console. Not in JSON format
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 97 def pretty_string [ "Rule:\t\t#{rule}", "Protocol:\t#{protocol}", "Action:\t\t#{action}", "CIDR Block:\t#{cidr_block}", if ports then "Ports:\t\t#{ports}" end, if icmp_type then "ICMP Type:\t#{icmp_type}" end, if icmp_code then "ICMP Code:\t#{icmp_code}" end, ].reject(&:nil?).join("\n") end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vpc/models/AclEntryConfig.rb', line 33 def to_hash { "rule" => @rule, "protocol" => @protocol, "action" => @action, "cidr-block" => @cidr_block, "ports" => @ports, "icmp-type" => @icmp_type, "icmp-code" => @icmp_code, }.reject { |k, v| v.nil? } end |