Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created January 5, 2022 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fujiwara/f4d7e30a1fdf79bb20f28a740f1d3b4f to your computer and use it in GitHub Desktop.
Save fujiwara/f4d7e30a1fdf79bb20f28a740f1d3b4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
def read_json(file_name)
JSON.parse(File.read(file_name))
end
def parse(iam)
result = []
iam["Statement"].each do |statement|
action = statement["Action"]
if !action.respond_to?(:each)
action = [action]
end
res = statement["Resource"]
if !res.respond_to?(:each)
res = [res]
end
res.each do |r|
action.each do |a|
result << "#{statement['Effect']} #{a} to #{r}"
end
end
end
result
end
from = read_json(ARGV[0])
to = read_json(ARGV[1])
from_set = parse(from)
to_set = parse(to)
minus = from_set - to_set
plus = to_set - from_set
if minus.empty? and plus.empty?
exit 0
else
puts "--- #{ARGV[0]}"
puts "+++ #{ARGV[1]}"
puts
end
minus.each do |diff|
puts "- #{diff}"
end
plus.each do |diff|
puts "+ #{diff}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment