Class: Cumulus::VPC::NetworkAclConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/vpc/models/NetworkAclConfig.rb

Overview

Public: An object representing configuration for a VPC Network ACL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, json = nil) ⇒ NetworkAclConfig

Public: Constructor

name - the name of the network acl config json - a hash containing the JSON configuration for the Network ACL



21
22
23
24
25
26
27
28
# File 'lib/vpc/models/NetworkAclConfig.rb', line 21

def initialize(name, json = nil)
  @name = name
  if !json.nil?
    @inbound = (json["inbound"] || []).map { |entry| AclEntryConfig.new(entry) }
    @outbound = (json["outbound"] || []).map { |entry| AclEntryConfig.new(entry) }
    @tags = json["tags"] || {}
  end
end

Instance Attribute Details

#inboundObject (readonly)

Returns the value of attribute inbound.



12
13
14
# File 'lib/vpc/models/NetworkAclConfig.rb', line 12

def inbound
  @inbound
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/vpc/models/NetworkAclConfig.rb', line 15

def name
  @name
end

#outboundObject (readonly)

Returns the value of attribute outbound.



13
14
15
# File 'lib/vpc/models/NetworkAclConfig.rb', line 13

def outbound
  @outbound
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/vpc/models/NetworkAclConfig.rb', line 14

def tags
  @tags
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

Returns an array of the NetworkAclDiffs that were found



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vpc/models/NetworkAclConfig.rb', line 62

def diff(aws)
  diffs = []

  aws_inbound = aws.diffable_entries.select { |entry| !entry.egress }
  inbound_diff = NetworkAclDiff.entries(NetworkAclChange::INBOUND, aws_inbound, @inbound)
  if inbound_diff
    diffs << inbound_diff
  end

  aws_outbound = aws.diffable_entries.select { |entry| entry.egress }
  outbound_diff = NetworkAclDiff.entries(NetworkAclChange::OUTBOUND, aws_outbound, @outbound)
  if outbound_diff
    diffs << outbound_diff
  end

  aws_tags = Hash[aws.tags.map { |tag| [tag.key, tag.value] }]
  if @tags != aws_tags
    diffs << NetworkAclDiff.new(NetworkAclChange::TAGS, aws_tags, @tags)
  end

  diffs
end

#populate!(aws) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vpc/models/NetworkAclConfig.rb', line 38

def populate!(aws)
  @inbound = aws.diffable_entries.select { |entry| !entry.egress }
                .map { |entry| AclEntryConfig.new().populate!(entry) }
                .sort_by!(&:rule)
  @outbound = aws.diffable_entries.select { |entry| entry.egress }
                .map { |entry| AclEntryConfig.new().populate!(entry) }
                .sort_by!(&:rule)
  @tags = Hash[aws.tags.map { |tag| [tag.key, tag.value] }]

  # If there is not a name then add a name tag using the given name
  if !@tags["Name"]
    puts "Network ACL #{aws.network_acl_id} does not have a Name defined. Cumulus will use #{name} as the name when migrated."
    @tags["Name"] = @name
  end

  self
end

#to_hashObject



30
31
32
33
34
35
36
# File 'lib/vpc/models/NetworkAclConfig.rb', line 30

def to_hash
  {
    "inbound" => @inbound.map(&:to_hash),
    "outbound" => @outbound.map(&:to_hash),
    "tags" => @tags
  }.reject { |k, v| v.nil? }
end