Module: AwsExtensions::IAM::Policy

Defined in:
lib/aws_extensions/iam/Policy.rb

Instance Method Summary collapse

Instance Method Details

#as_hashObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/aws_extensions/iam/Policy.rb', line 7

def as_hash
  # Sort the statments to prevent false conflicts while diffing
  sorted_policy = JSON.parse(URI.unescape(policy_document))
  sorted_policy["Statement"].each do |statement|
    # actions sometimes contains a single string element instead of the expected array
    statement["Action"] = [statement["Action"]] if statement["Action"].is_a? String
    # resources sometimes contains a single string element instead of the expected array
    statement["Resource"] = [statement["Resource"]] if statement["Resource"].is_a? String
  end
  # return the sorted policy hash
  sorted_policy.deep_sort
end