Class: CfnNag
- Inherits:
-
Object
show all
- Includes:
- Rule
- Defined in:
- lib/cfn_nag.rb
Instance Attribute Summary
Attributes included from Rule
#input_json_path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Rule
#add_violation, #assertion, count_failures, count_warnings, empty?, #fatal_assertion, #fatal_violation, #raw_fatal_assertion, #raw_fatal_violation, #resources, #resources_by_type, #violation, #warning
Constructor Details
#initialize ⇒ CfnNag
Returns a new instance of CfnNag.
13
14
15
16
|
# File 'lib/cfn_nag.rb', line 13
def initialize
@warning_registry = []
@violation_registry = []
end
|
Class Method Details
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/cfn_nag.rb', line 77
def self.configure_logging(opts)
logger = Logging.logger['log']
if opts[:debug]
logger.level = :debug
else
logger.level = :info
end
logger.add_appenders Logging.appenders.stdout
end
|
Instance Method Details
#audit(input_json_path:, output_format: 'txt') ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/cfn_nag.rb', line 49
def audit(input_json_path:,
output_format:'txt')
aggregate_results = audit_results input_json_path: input_json_path,
output_format: output_format
aggregate_results.inject(0) { |total_failure_count, results| total_failure_count + results[:file_results][:failure_count] }
end
|
#audit_results(input_json_path:, output_format: 'txt') ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/cfn_nag.rb', line 58
def audit_results(input_json_path:,
output_format:'txt')
templates = discover_templates(input_json_path)
aggregate_results = []
templates.each do |template|
aggregate_results << {
filename: template,
file_results: audit_file(input_json_path: template)
}
end
render_results(aggregate_results: aggregate_results,
output_format: output_format)
aggregate_results
end
|
#dump_rules ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/cfn_nag.rb', line 18
def dump_rules
dummy_cfn = <<-END
{
"Resources": {
"resource1": {
"Type" : "AWS::EC2::DHCPOptions",
"Properties": {
"DomainNameServers" : [ "10.0.0.1" ]
}
}
}
}
END
Tempfile.open('tempfile') do |dummy_cfn_template|
dummy_cfn_template.write dummy_cfn
dummy_cfn_template.rewind
audit_file(input_json_path: dummy_cfn_template.path)
end
custom_rule_registry.each do |rule_class|
@violation_registry << rule_class.new.rule_text
end
puts 'WARNING VIOLATIONS:'
puts @warning_registry.sort
puts
puts 'FAILING VIOLATIONS:'
puts @violation_registry.sort
end
|