Skip to content

Commit

Permalink
Merge pull request #11 from sylvation/fix_assumed_role_sort
Browse files Browse the repository at this point in the history
fix for issue #10
  • Loading branch information
Genki Sugawara committed Nov 13, 2015
2 parents 7203226 + f947d18 commit 581ccc8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/miam/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def walk_role(role_name, expected_attrs, actual_attrs)

def walk_assume_role_policy(role_name, expected_assume_role_policy, actual_assume_role_policy)
updated = false
expected_assume_role_policy = recursively_sort_arrays_and_hashes(expected_assume_role_policy)
actual_assume_role_policy = recursively_sort_arrays_and_hashes(actual_assume_role_policy)

if expected_assume_role_policy != actual_assume_role_policy
@driver.update_assume_role_policy(role_name, expected_assume_role_policy, actual_assume_role_policy)
Expand Down Expand Up @@ -469,6 +471,17 @@ def exec_by_format(proc_by_format)
format_proc.call
end

def recursively_sort_arrays_and_hashes(obj)
case obj
when Array
obj.map!{|v| recursively_sort_arrays_and_hashes(v)}.sort_by!{|v| (v.to_s rescue nil) }
when Hash
obj = Hash[Hash[obj.map{|k,v| [recursively_sort_arrays_and_hashes(k),recursively_sort_arrays_and_hashes(v)]}].sort_by{|k,v| [(k.to_s rescue nil), (v.to_s rescue nil)]}]
else
obj
end
end

def load_json(json)
json = JSON.load(json)
normalized = {}
Expand All @@ -493,6 +506,7 @@ def load_json(json)
end
end


normalized
end
end

0 comments on commit 581ccc8

Please sign in to comment.