Class: ProfileLoader

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

Instance Method Summary collapse

Constructor Details

#initialize(rules_registry) ⇒ ProfileLoader

Returns a new instance of ProfileLoader.



5
6
7
# File 'lib/cfn-nag/profile_loader.rb', line 5

def initialize(rules_registry)
  @rules_registry = rules_registry
end

Instance Method Details

#load(profile_definition:) ⇒ Object



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

def load(profile_definition:)

  if profile_definition.nil? or profile_definition.strip == ''
    raise 'Empty profile'
  end

  new_profile = Profile.new

  profile_definition.each_line do |line|
    rule_id = line.chomp
    if @rules_registry.by_id(rule_id) == nil
      raise "#{rule_id} is not a legal rule identifier from: #{@rules_registry.rules.map { |rule| rule.id }}"
    else
      new_profile.add_rule rule_id
    end
  end
  new_profile
end