Class: Cumulus::VPC::NetworkAclDiff

Inherits:
Common::Diff show all
Includes:
Common::TagsDiff, NetworkAclChange
Defined in:
lib/vpc/models/NetworkAclDiff.rb

Overview

Public: Represents a single difference between local configuration and AWS configuration

Constant Summary

Constants included from NetworkAclChange

Cumulus::VPC::NetworkAclChange::INBOUND, Cumulus::VPC::NetworkAclChange::OUTBOUND, Cumulus::VPC::NetworkAclChange::TAGS

Constants included from Common::DiffChange

Common::DiffChange::ADD, Common::DiffChange::MODIFIED, Common::DiffChange::UNMANAGED

Instance Attribute Summary

Attributes inherited from Common::Diff

#aws, #changes, #info_only, #local, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::TagsDiff

#tags_diff_string, #tags_to_add, #tags_to_remove

Methods included from Common::DiffChange

next_change_id

Methods inherited from Common::Diff

#add_string, added, #initialize, #local_name, modified, #to_s, unmanaged, #unmanaged_string

Constructor Details

This class inherits a constructor from Cumulus::Common::Diff

Class Method Details

.entries(type, aws, local) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vpc/models/NetworkAclDiff.rb', line 25

def self.entries(type, aws, local)
  aws_rule_entries = Hash[aws.map do |entry|
    aws_entry = AclEntryConfig.new
    aws_entry.populate!(entry)
    [entry.rule_number, aws_entry]
  end]
  local_rule_entries = Hash[local.map { |entry| [entry.rule, entry] }]

  added_diffs = Hash[local_rule_entries.reject { |rule, entry| aws_rule_entries.has_key? rule }.map do |rule, local_entry|
    [rule, AclEntryDiff.added(local_entry)]
  end]
  removed_diffs = Hash[aws_rule_entries.reject { |rule, entry| local_rule_entries.has_key? rule }.map do |rule, aws_entry|
    [rule, AclEntryDiff.unmanaged(aws_entry)]
  end]

  modified_diffs = Hash[local_rule_entries.select { |rule, entry| aws_rule_entries.has_key? rule }.map do |rule, local_entry|
    aws_entry = aws_rule_entries[rule]
    entry_diffs = local_entry.diff(aws_entry)
    if !entry_diffs.empty?
      [rule, AclEntryDiff.modified(aws_entry, local_entry, entry_diffs)]
    end
  end.reject { |v| v.nil? }]

  if !added_diffs.empty? or !removed_diffs.empty? or !modified_diffs.empty?
    diff = NetworkAclDiff.new(type, aws, local)
    diff.changes = Common::ListChange.new(added_diffs, removed_diffs, modified_diffs)
    diff
  end
end

Instance Method Details

#asset_typeObject



63
64
65
# File 'lib/vpc/models/NetworkAclDiff.rb', line 63

def asset_type
  "Network Acl"
end

#aws_nameObject



67
68
69
# File 'lib/vpc/models/NetworkAclDiff.rb', line 67

def aws_name
  @aws.name || @aws.network_acl_id
end

#aws_tagsObject



59
60
61
# File 'lib/vpc/models/NetworkAclDiff.rb', line 59

def aws_tags
  @aws
end

#diff_stringObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vpc/models/NetworkAclDiff.rb', line 71

def diff_string
  case @type
  when INBOUND
    [
      "Inbound Rules:",
      entries_diff_string
    ].flatten.join("\n")
  when OUTBOUND
    [
      "Outbound Rules:",
      entries_diff_string
    ].flatten.join("\n")
  when TAGS
    tags_diff_string
  end
end

#local_tagsObject



55
56
57
# File 'lib/vpc/models/NetworkAclDiff.rb', line 55

def local_tags
  @local
end