1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Fix get_user_policy. The actual AWS data has to be in a ['Policy'] hash section

This commit is contained in:
Rodrigo Estebanez 2012-06-07 14:40:34 +02:00
parent 6aa7efb56f
commit 3a175f177f
3 changed files with 10 additions and 9 deletions

View file

@ -22,13 +22,13 @@ module Fog
policy_names = connection.list_user_policies(@username).body['PolicyNames'] # it returns an array
policies = []
policy_names.each do |policy_name|
policies << connection.get_user_policy(policy_name,@username).body
policies << connection.get_user_policy(policy_name,@username).body['Policy']
end
load(policies) # data is an array of attribute hashes
end
def get(identity)
data = connection.get_user_policy(identity,@username).body
data = connection.get_user_policy(identity,@username).body['Policy']
new(data) # data is an attribute hash
rescue Fog::AWS::IAM::NotFound
nil

View file

@ -7,15 +7,15 @@ module Fog
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetUserPolicy.html
def reset
@response = {}
@response = { 'Policy' => {} }
end
def end_element(name)
case name
when 'UserName', 'PolicyName'
@response[name] = value
@response['Policy'][name] = value
when 'PolicyDocument'
@response[name] = if decoded_string = URI.decode(value)
@response['Policy'][name] = if decoded_string = URI.decode(value)
Fog::JSON.decode(decoded_string) rescue value
else
value

View file

@ -36,10 +36,11 @@ module Fog
raise Fog::AWS::IAM::NotFound.new("The user with name #{user} cannot be found.") unless self.data[:users].key?(user_name)
raise Fog::AWS::IAM::NotFound.new("The policy with name #{policy_name} cannot be found.") unless self.data[:users][user_name][:policies].key?(policy_name)
Excon::Response.new.tap do |response|
response.body = {
'PolicyName' => policy_name,
'UserName' => user_name,
'PolicyDocument' => data[:users][user_name][:policies][policy_name],
response.body = { 'Policy' => {
'PolicyName' => policy_name,
'UserName' => user_name,
'PolicyDocument' => data[:users][user_name][:policies][policy_name]
},
'IsTruncated' => false,
'RequestId' => Fog::AWS::Mock.request_id
}