From 6ccacadcd37b89434e0d3b2c929e12a1cb556a3a Mon Sep 17 00:00:00 2001 From: aibou Date: Fri, 1 Jun 2018 11:18:50 +0900 Subject: [PATCH] Fix a bug: can not export over 100 rules #4 --- lib/monosasi/exporter.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/monosasi/exporter.rb b/lib/monosasi/exporter.rb index 09a3c9b..fc7e4fb 100644 --- a/lib/monosasi/exporter.rb +++ b/lib/monosasi/exporter.rb @@ -16,23 +16,28 @@ def export def export_rules rule_by_name = {} - resp = @client.list_rules + next_token = nil + loop do + resp = @client.list_rules(next_token: next_token) - Parallel.each(resp.rules, in_threads: CONCURRENCY) do |rule| - rule = rule.to_h - rule.delete(:arn) - rule_name = rule.delete(:name) + Parallel.each(resp.rules, in_threads: CONCURRENCY) do |rule| + rule = rule.to_h + rule.delete(:arn) + rule_name = rule.delete(:name) - next unless target?(rule_name) + next unless target?(rule_name) - if rule[:event_pattern] - rule[:event_pattern] = JSON.parse(rule[:event_pattern]) - end + if rule[:event_pattern] + rule[:event_pattern] = JSON.parse(rule[:event_pattern]) + end + + targets = export_targets(rule_name) + rule[:targets] = targets - targets = export_targets(rule_name) - rule[:targets] = targets + rule_by_name[rule_name] = rule + end - rule_by_name[rule_name] = rule + break if (next_token = resp.next_token).nil? end rule_by_name