Class: CustomRuleLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/custom_rule_loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule_registry) ⇒ CustomRuleLoader

Returns a new instance of CustomRuleLoader.



21
22
23
24
25
26
27
28
29
30
# File 'lib/custom_rule_loader.rb', line 21

def initialize(rule_registry)
  @custom_rule_registry = [
    SecurityGroupMissingEgressRule,
    UserMissingGroupRule,
    UnencryptedS3PutObjectAllowedRule
  ]
  @violations = []
  @rule_registry = rule_registry
  discover_rules
end

Instance Attribute Details

#custom_rule_registryObject (readonly)

Returns the value of attribute custom_rule_registry.



9
10
11
# File 'lib/custom_rule_loader.rb', line 9

def custom_rule_registry
  @custom_rule_registry
end

Class Method Details

.custom_rule_directoryObject



17
18
19
# File 'lib/custom_rule_loader.rb', line 17

def self.custom_rule_directory
  @custom_rule_directory
end

.custom_rule_directory=(directory) ⇒ Object



13
14
15
# File 'lib/custom_rule_loader.rb', line 13

def self.custom_rule_directory=(directory)
  @custom_rule_directory = directory
end

Instance Method Details

#custom_rules(input_json) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/custom_rule_loader.rb', line 32

def custom_rules(input_json)
  @violations = []

  @custom_rule_registry.each do |rule_class|
    rule = rule_class.new
    @rule_registry.definition(id: rule.rule_id,
                              type: rule.rule_type,
                              message: rule.rule_text)

    if rule.respond_to? 'custom_parsers'
      rule.custom_parsers.each do |custom_parser|
        ParserRegistry.instance.add_parser custom_parser[0], custom_parser[1]
      end
    end

    cfn_model = CfnModel.new.parse(input_json)
    audit_result = rule_class.new.audit(cfn_model)
    @violations << audit_result unless audit_result.nil?
  end
  @violations
end