cfn-nag 0.3.30 → 0.3.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59441006b3494befe307a988a3150c7a06703f0e
4
- data.tar.gz: 18e6b6b11833b57d0df2dd39e0d775bc75e4aaae
3
+ metadata.gz: bf68cbb1d8b4e0711fb0ef50f053223f65e14b24
4
+ data.tar.gz: d4b56316b952e80a7098932fd05b2397e80a7a72
5
5
  SHA512:
6
- metadata.gz: 8b35ab8943567fb61efbf17d343d94a5be75c09872f617427d18f47a3e88b1b8bb412ece9decf5e846d8cd9d9477f043670221d2dfec7c8e820b6c9a4509ad8e
7
- data.tar.gz: 8e96a3dd3f4a9ecbde34fc26375e3b1606be038b97bc46711e26e3f305404e51df1c408713aa2a59e5086f7815d1913ff5a784e370fdea99163ee9b91e2edeac
6
+ metadata.gz: 2d484bb7b0ee1fce0a49ffc3fb05184dfb8cf2756e8d63f6f65c3b5b9379645638767273c51fb26699a314a9005e7def27fd190caf3df2b0d87cd9dea8a8366a
7
+ data.tar.gz: 6df463d3d3f978703ac68cb2ea5930f163ee9ace24241920ecc22787a8fde571caf7f622530a54d0319a6bf8c1226c2c1ddace9ef5da6a2159484188724c819b
@@ -1,26 +1,35 @@
1
+ # View rules warnings/failings
1
2
  class RulesView
2
3
  def emit(rule_registry, profile)
3
4
  puts 'WARNING VIOLATIONS:'
4
- rule_registry.warnings.sort { |left, right| sort_id(left, right) }.each do |warning|
5
+ emit_warnings rule_registry.warnings, profile
6
+ puts
7
+ puts 'FAILING VIOLATIONS:'
8
+ emit_failings rule_registry.failings, profile
9
+ end
10
+
11
+ private
12
+
13
+ def emit_warnings(warnings, profile)
14
+ warnings.sort { |left, right| sort_id(left, right) }.each do |warning|
5
15
  if profile.nil?
6
16
  puts "#{warning.id} #{warning.message}"
7
- else
8
- puts "#{warning.id} #{warning.message}" if profile.execute_rule?(warning.id)
17
+ elsif profile.execute_rule?(warning.id)
18
+ puts "#{warning.id} #{warning.message}"
9
19
  end
10
20
  end
11
- puts
12
- puts 'FAILING VIOLATIONS:'
13
- rule_registry.failings.sort { |left, right| sort_id(left, right) }.each do |failing|
21
+ end
22
+
23
+ def emit_failings(failings, profile)
24
+ failings.sort { |left, right| sort_id(left, right) }.each do |failing|
14
25
  if profile.nil?
15
26
  puts "#{failing.id} #{failing.message}"
16
- else
17
- puts "#{failing.id} #{failing.message}" if profile.execute_rule?(failing.id)
27
+ elsif profile.execute_rule?(failing.id)
28
+ puts "#{failing.id} #{failing.message}"
18
29
  end
19
30
  end
20
31
  end
21
32
 
22
- private
23
-
24
33
  def sort_id(left, right)
25
34
  if left.id.match(/[FW][0-9]+/) && right.id.match(/[FW][0-9]+/)
26
35
  left.id[1..-1].to_i <=> right.id[1..-1].to_i
@@ -1,19 +1,34 @@
1
1
  require 'cfn-nag/violation'
2
2
 
3
+ # Print results to STDOUT
3
4
  class SimpleStdoutResults
5
+ def message_violations(violations)
6
+ violations.each do |violation|
7
+ message message_type: "#{violation.type} #{violation.id}",
8
+ message: violation.message,
9
+ logical_resource_ids: violation.logical_resource_ids
10
+ end
11
+ end
12
+
13
+ def print_failures(violations)
14
+ puts "\nFailures count: #{Violation.count_failures(violations)}"
15
+ end
16
+
17
+ def print_warnings(violations)
18
+ puts "Warnings count: #{Violation.count_warnings(violations)}"
19
+ end
20
+
4
21
  def render(results)
5
22
  results.each do |result|
6
23
  60.times { print '-' }
7
24
  puts "\n" + result[:filename]
8
25
  60.times { print '-' }
9
26
 
10
- result[:file_results][:violations].each do |violation|
11
- message message_type: "#{violation.type} #{violation.id}",
12
- message: violation.message,
13
- logical_resource_ids: violation.logical_resource_ids
14
- end
15
- puts "\nFailures count: #{Violation.count_failures(result[:file_results][:violations])}"
16
- puts "Warnings count: #{Violation.count_warnings(result[:file_results][:violations])}"
27
+ violations = result[:file_results][:violations]
28
+
29
+ message_violations violations
30
+ print_failures violations
31
+ print_warnings violations
17
32
  end
18
33
  end
19
34
 
@@ -1,21 +1,21 @@
1
+ # Container for discovering templates
1
2
  class TemplateDiscovery
3
+ # input_json_path can be a directory, filename, or File
2
4
  def discover_templates(input_json_path)
3
5
  if ::File.directory? input_json_path
4
- templates = find_templates_in_directory(directory: input_json_path)
5
- elsif ::File.file? input_json_path
6
- templates = if input_json_path.is_a? File
7
- [input_json_path.path]
8
- else
9
- [input_json_path]
10
- end
11
- else
12
- raise "#{input_json_path} is not a proper path"
6
+ return find_templates_in_directory(directory: input_json_path)
13
7
  end
14
- templates
8
+ return [render_path(input_json_path)] if ::File.file? input_json_path
9
+ raise "#{input_json_path} is not a proper path"
15
10
  end
16
11
 
17
12
  private
18
13
 
14
+ def render_path(path)
15
+ return path.path if path.is_a? File
16
+ path
17
+ end
18
+
19
19
  def find_templates_in_directory(directory:,
20
20
  cfn_extensions: %w[json yaml yml template])
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-nag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.30
4
+ version: 0.3.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic