class ProfileLoader
Public Class Methods
new(rules_registry)
click to toggle source
# File lib/cfn-nag/profile_loader.rb, line 6 def initialize(rules_registry) @rules_registry = rules_registry end
Public Instance Methods
load(profile_definition:)
click to toggle source
Load rules from a profile definition
# File lib/cfn-nag/profile_loader.rb, line 11 def load(profile_definition:) # coerce falsy profile_definition into empty string for # empty profile check profile_definition ||= '' raise 'Empty profile' if profile_definition.strip == '' new_profile = RuleIdSet.new profile_definition.each_line do |line| next unless (rule_id = rule_line_match(line)) check_valid_rule_id rule_id new_profile.add_rule rule_id end new_profile end
Private Instance Methods
check_valid_rule_id(rule_id)
click to toggle source
Return true if rule_id is valid (present in rules registry), else raise an error
# File lib/cfn-nag/profile_loader.rb, line 47 def check_valid_rule_id(rule_id) return true unless @rules_registry.by_id(rule_id).nil? raise "#{rule_id} is not a legal rule identifier from: #{rules_ids}" end
rule_line_match(rule_id)
click to toggle source
Parses a line, returns first matching line or false if no match
# File lib/cfn-nag/profile_loader.rb, line 32 def rule_line_match(rule_id) rule_id = rule_id.chomp matches = /^([a-zA-Z]*?[0-9]+)\s*(.*)/.match(rule_id) return false if matches.nil? matches.captures.first end
rules_ids()
click to toggle source
Return ids of rules in registry
# File lib/cfn-nag/profile_loader.rb, line 41 def rules_ids @rules_registry.rules.map(&:id) end