cfn-nag 0.3.39 → 0.3.40

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
  SHA256:
3
- metadata.gz: 2843c50fa4d415aedb5606961c12ab5646a1fa75aa9c919bf66d29fea086e4f0
4
- data.tar.gz: 748fa1657a3f5c77915983ea5aee06cc569114719338226bd76646f51c46ea69
3
+ metadata.gz: 6c5f5526f00bdcb756ccda1d679afe742fa2ea77a5858eb86fb5d1b8216a89b8
4
+ data.tar.gz: 307512c7fe5ea5de57323c68e7aeab2646026c4d2411c41e5f6b9da9f066b243
5
5
  SHA512:
6
- metadata.gz: e0550dc541239547c330aa2ee983a8f787ca02d5b8f4b4b6646bbe8e0a511a8f9be53b12df5ced20168ab85b50df3941e5d35d10d310f64a9d146a1b304b7baa
7
- data.tar.gz: 65534e73756b15adb8c9a980af95efb3185a8d2d01075f4f49a0d8552341a43170d6d7a599c25a410fcbba365cbabc32807dd400b6319a75a5aef453c52508a7
6
+ metadata.gz: 38392d3069353e411ad7a4bff68113f0420ccf1ad2ae6ae3288d3510214114e3d339bf9110a267a5e41d74ea612d5b0900fe7c1d69c554b3cffafa15a8b959ec
7
+ data.tar.gz: 5057bb311c09bd37e9271f6e4ec02822e189416fabac9abf0ca718d679432303f8ede7bf45118f9ac661c0f66e6d085833415b274e2cbf7e4b90b29b4887fe51
@@ -18,7 +18,6 @@ class S3BucketPolicyWildcardActionRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::S3::BucketPolicy').each do |bucket_policy|
21
-
22
21
  if !bucket_policy.policy_document.wildcard_allowed_actions.empty?
23
22
  logical_resource_ids << bucket_policy.logical_resource_id
24
23
  end
@@ -18,7 +18,6 @@ class SqsQueuePolicyWildcardActionRule < BaseRule
18
18
  logical_resource_ids = []
19
19
 
20
20
  cfn_model.resources_by_type('AWS::SQS::QueuePolicy').each do |queue_policy|
21
-
22
21
  if !queue_policy.policy_document.wildcard_allowed_actions.empty?
23
22
  logical_resource_ids << queue_policy.logical_resource_id
24
23
  end
@@ -1,30 +1,48 @@
1
1
  require_relative 'profile'
2
2
 
3
+ # Load rule profile
3
4
  class ProfileLoader
4
5
  def initialize(rules_registry)
5
6
  @rules_registry = rules_registry
6
7
  end
7
8
 
9
+ # Load rules from a profile definition
8
10
  def load(profile_definition:)
9
- if profile_definition.nil? || (profile_definition.strip == '')
10
- raise 'Empty profile'
11
- end
11
+ # coerce falsy profile_definition into empty string for
12
+ # empty profile check
13
+ profile_definition ||= ''
14
+ raise 'Empty profile' if profile_definition.strip == ''
12
15
 
13
16
  new_profile = Profile.new
14
17
 
15
18
  profile_definition.each_line do |line|
16
- rule_id = line.chomp
17
- rule_line_match = /^([a-zA-Z]*?[0-9]+)\s*(.*)/.match(rule_id)
18
- if !rule_line_match.nil?
19
- rule_id = rule_line_match.captures.first
20
- if @rules_registry.by_id(rule_id) == nil
21
- raise "#{rule_id} is not a legal rule identifier from: " \
22
- "#{@rules_registry.rules.map(&:id)}"
23
- else
24
- new_profile.add_rule rule_id
25
- end
26
- end
19
+ next unless (rule_id = rule_line_match(line))
20
+ check_valid_rule_id rule_id
21
+ new_profile.add_rule rule_id
27
22
  end
28
23
  new_profile
29
24
  end
25
+
26
+ private
27
+
28
+ # Parses a line, returns first matching line or false if
29
+ # no match
30
+ def rule_line_match(rule_id)
31
+ rule_id = rule_id.chomp
32
+ matches = /^([a-zA-Z]*?[0-9]+)\s*(.*)/.match(rule_id)
33
+ return false if matches.nil?
34
+ matches.captures.first
35
+ end
36
+
37
+ # Return ids of rules in registry
38
+ def rules_ids
39
+ @rules_registry.rules.map(&:id)
40
+ end
41
+
42
+ # Return true if rule_id is valid (present in rules registry),
43
+ # else raise an error
44
+ def check_valid_rule_id(rule_id)
45
+ return true unless @rules_registry.by_id(rule_id).nil?
46
+ raise "#{rule_id} is not a legal rule identifier from: #{rules_ids}"
47
+ end
30
48
  end
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.39
4
+ version: 0.3.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kascic