mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2240 from josacar/master
Behave IAM policy group methods like user policy
This commit is contained in:
commit
80f150d428
7 changed files with 65 additions and 18 deletions
|
@ -102,7 +102,9 @@ module Fog
|
|||
ghash[gkey] = {
|
||||
:group_id => Fog::AWS::Mock.key_id,
|
||||
:arn => "arn:aws:iam::#{Fog::AWS::Mock.owner_id}:group/#{gkey}",
|
||||
:members => []
|
||||
:members => [],
|
||||
:created_at => Time.now,
|
||||
:policies => {}
|
||||
}
|
||||
end
|
||||
}
|
||||
|
|
|
@ -7,15 +7,21 @@ module Fog
|
|||
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetGroupPolicy.html
|
||||
|
||||
def reset
|
||||
@response = {}
|
||||
@response = { 'Policy' => {} }
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'GroupName', 'PolicyName', 'PolicyDocument'
|
||||
@response[name] = @value
|
||||
when 'GroupName', 'PolicyName'
|
||||
@response[name] = value
|
||||
when 'PolicyDocument'
|
||||
@response['Policy'][name] = if decoded_string = URI.decode(value)
|
||||
Fog::JSON.decode(decoded_string) rescue value
|
||||
else
|
||||
value
|
||||
end
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
@response[name] = value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
require 'fog/aws/parsers/iam/get_group_policy'
|
||||
|
||||
# Get Group Policy
|
||||
#
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'PolicyName'<~String>: Name of the policy to get
|
||||
# * 'GroupName'<~String>: Name of the Group who the policy is associated with.
|
||||
|
@ -31,6 +31,23 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def get_group_policy(policy_name, group_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.") unless self.data[:groups].key?(group_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The policy with name #{policy_name} cannot be found.") unless self.data[:groups][group_name][:policies].key?(policy_name)
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'Policy' => {
|
||||
'PolicyName' => policy_name,
|
||||
'GroupName' => group_name,
|
||||
'PolicyDocument' => data[:groups][group_name][:policies][policy_name]
|
||||
},
|
||||
'IsTruncated' => false,
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
require 'fog/aws/parsers/iam/get_user_policy'
|
||||
|
||||
# Get User Policy
|
||||
#
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'PolicyName'<~String>: Name of the policy to get
|
||||
# * 'UserName'<~String>: Name of the User who the policy is associated with.
|
||||
|
@ -33,16 +33,16 @@ module Fog
|
|||
end
|
||||
class Mock
|
||||
def get_user_policy(policy_name, user_name)
|
||||
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 user with name #{user_name} 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 = { 'Policy' => {
|
||||
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
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response.status = 200
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Add or update a policy for a group
|
||||
#
|
||||
#
|
||||
# ==== Parameters
|
||||
# * group_name<~String>: name of the group
|
||||
# * policy_name<~String>: name of policy document
|
||||
|
@ -31,6 +31,22 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
#FIXME: You can't actually use the credentials for anything elsewhere in Fog
|
||||
#FIXME: Doesn't do any validation on the policy
|
||||
def put_group_policy(group_name, policy_name, policy_document)
|
||||
if data[:groups].has_key? group_name
|
||||
data[:groups][group_name][:policies][policy_name] = policy_document
|
||||
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
else
|
||||
raise Fog::AWS::IAM::NotFound.new("The group with name #{group_name} cannot be found.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
|||
require 'fog/aws/parsers/iam/basic'
|
||||
|
||||
# Add or update a policy for a user
|
||||
#
|
||||
#
|
||||
# ==== Parameters
|
||||
# * user_name<~String>: name of the user
|
||||
# * policy_name<~String>: name of policy document
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
Shindo.tests('AWS::IAM | group policy requests', ['aws']) do
|
||||
|
||||
unless Fog.mocking?
|
||||
Fog::AWS[:iam].create_group('fog_group_policy_tests')
|
||||
end
|
||||
Fog::AWS[:iam].create_group('fog_group_policy_tests')
|
||||
|
||||
tests('success') do
|
||||
|
||||
@policy = {"Statement" => [{"Effect" => "Allow", "Action" => "*", "Resource" => "*"}]}
|
||||
|
||||
tests("#put_group_policy('fog_group_policy_tests', 'fog_policy', #{@policy.inspect})").formats(AWS::IAM::Formats::BASIC) do
|
||||
pending if Fog.mocking?
|
||||
Fog::AWS[:iam].put_group_policy('fog_group_policy_tests', 'fog_policy', @policy).body
|
||||
end
|
||||
|
||||
|
@ -24,11 +21,20 @@ Shindo.tests('AWS::IAM | group policy requests', ['aws']) do
|
|||
Fog::AWS[:iam].list_group_policies('fog_group_policy_tests').body
|
||||
end
|
||||
|
||||
@group_policy_format = {
|
||||
'GroupName' => String,
|
||||
'PolicyName' => String,
|
||||
'PolicyDocument' => Hash,
|
||||
}
|
||||
|
||||
tests("#get_group_policy('fog_group_policy_tests', 'fog_policy'").formats(@group_policy_format) do
|
||||
Fog::AWS[:iam].get_group_policy('fog_policy', 'fog_group_policy_tests').body['Policy']
|
||||
end
|
||||
|
||||
tests("#delete_group_policy('fog_group_policy_tests', 'fog_policy')").formats(AWS::IAM::Formats::BASIC) do
|
||||
pending if Fog.mocking?
|
||||
Fog::AWS[:iam].delete_group_policy('fog_group_policy_tests', 'fog_policy').body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
@ -39,4 +45,4 @@ Shindo.tests('AWS::IAM | group policy requests', ['aws']) do
|
|||
Fog::AWS[:iam].delete_group('fog_group_policy_tests')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue