Skip to content

Commit

Permalink
stelligent#400 emit s3 loading debug info when --debug is set
Browse files Browse the repository at this point in the history
  • Loading branch information
erickascic committed Mar 9, 2020
1 parent 9935854 commit 3feaf05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/cfn-nag/rule_repos/s3_based_rule_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'aws-sdk-s3'
require 'lightly'
require 'json'
require 'logging'
require_relative '../rule_registry'
require_relative '../rule_repo_exception'

Expand Down Expand Up @@ -42,9 +43,13 @@ def initialize(s3_bucket_name:, prefix:, index_lifetime: '1h', aws_profile: nil)
end

def discover_rules
Logging.logger['log'].debug "S3BucketBasedRuleRepo.discover_rules in #{@s3_bucket_name}, #{@prefix}"

rule_registry = RuleRegistry.new

index = index(@s3_bucket_name, @prefix)
Logging.logger['log'].debug "index: #{index}"

index.each do |rule_object_key|
rule_code = @rule_cache.get(rule_object_key) do
cache_miss(rule_object_key)
Expand All @@ -71,6 +76,8 @@ def nuke_cache
private

def cache_miss(key)
Logging.logger['log'].debug "cache_miss: #{key}"

rule_code_record = s3_object_content(@s3_bucket_name, key)
rule_code_record.body.read
end
Expand Down Expand Up @@ -111,6 +118,7 @@ def discover_rule_s3_objects(s3_bucket_name, prefix)
rule_objects = objects.select do |object|
object.key.match(/.*Rule\.rb/)
end
Logging.logger['log'].debug "Found rule objects: #{rule_objects}"
rule_objects.map(&:key)
rescue Aws::S3::Errors::NoSuchBucket
raise RuleRepoException.new(msg: "Rule bucket not found: #{s3_bucket_name}")
Expand Down

0 comments on commit 3feaf05

Please sign in to comment.