Class: BlackListLoader

Inherits:
Object show all
Defined in:
lib/cfn-nag/blacklist_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(rules_registry) ⇒ BlackListLoader

Returns a new instance of BlackListLoader.


6
7
8
# File 'lib/cfn-nag/blacklist_loader.rb', line 6

def initialize(rules_registry)
  @rules_registry = rules_registry
end

Instance Method Details

#load(blacklist_definition:) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cfn-nag/blacklist_loader.rb', line 10

def load(blacklist_definition:)
  raise 'Empty profile' if blacklist_definition.strip == ''

  blacklist_ruleset = RuleIdSet.new

  blacklist_hash = load_blacklist_yaml(blacklist_definition)
  raise 'Blacklist is malformed' unless blacklist_hash.is_a? Hash

  rules_to_suppress = blacklist_hash.fetch('RulesToSuppress', {})
  raise 'Missing RulesToSuppress key in black list' if rules_to_suppress.empty?

  rule_ids_to_suppress = rules_to_suppress.map { |rule| rule['id'] }
  rule_ids_to_suppress.each do |rule_id|
    check_valid_rule_id rule_id
    blacklist_ruleset.add_rule rule_id
  end

  blacklist_ruleset
end