mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] user policy requests/tests
This commit is contained in:
parent
432361b33b
commit
c83e1bae00
7 changed files with 174 additions and 3 deletions
|
@ -13,11 +13,14 @@ module Fog
|
||||||
request :delete_group
|
request :delete_group
|
||||||
request :delete_group_policy
|
request :delete_group_policy
|
||||||
request :delete_user
|
request :delete_user
|
||||||
|
request :delete_user_policy
|
||||||
request :list_access_keys
|
request :list_access_keys
|
||||||
request :list_groups
|
request :list_groups
|
||||||
request :list_group_policies
|
request :list_group_policies
|
||||||
|
request :list_user_policies
|
||||||
request :list_users
|
request :list_users
|
||||||
request :put_group_policy
|
request :put_group_policy
|
||||||
|
request :put_user_policy
|
||||||
request :remove_user_from_group
|
request :remove_user_from_group
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Fog
|
||||||
module AWS
|
module AWS
|
||||||
module IAM
|
module IAM
|
||||||
|
|
||||||
class ListGroupPolicies < Fog::Parsers::Base
|
class ListPolicies < Fog::Parsers::Base
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
@response = { 'PolicyNames' => [] }
|
@response = { 'PolicyNames' => [] }
|
42
lib/fog/aws/requests/iam/delete_user_policy.rb
Normal file
42
lib/fog/aws/requests/iam/delete_user_policy.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class IAM
|
||||||
|
class Real
|
||||||
|
|
||||||
|
require 'fog/aws/parsers/iam/basic'
|
||||||
|
|
||||||
|
# Remove a policy from a user
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * user_name<~String>: name of the user
|
||||||
|
# * policy_name<~String>: name of policy document
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'RequestId'<~String> - Id of the request
|
||||||
|
#
|
||||||
|
# ==== See Also
|
||||||
|
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteUserPolicy.html
|
||||||
|
#
|
||||||
|
def delete_user_policy(user_name, policy_name)
|
||||||
|
request(
|
||||||
|
'Action' => 'DeleteUserPolicy',
|
||||||
|
'PolicyName' => policy_name,
|
||||||
|
'UserName' => user_name,
|
||||||
|
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def delete_user_policy(user_name, policy_name)
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,7 +3,7 @@ module Fog
|
||||||
class IAM
|
class IAM
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
require 'fog/aws/parsers/iam/list_group_policies'
|
require 'fog/aws/parsers/iam/list_policies'
|
||||||
|
|
||||||
# List policies for a group
|
# List policies for a group
|
||||||
#
|
#
|
||||||
|
@ -29,7 +29,7 @@ module Fog
|
||||||
request({
|
request({
|
||||||
'Action' => 'ListGroupPolicies',
|
'Action' => 'ListGroupPolicies',
|
||||||
'GroupName' => group_name,
|
'GroupName' => group_name,
|
||||||
:parser => Fog::Parsers::AWS::IAM::ListGroupPolicies.new
|
:parser => Fog::Parsers::AWS::IAM::ListPolicies.new
|
||||||
}.merge!(options))
|
}.merge!(options))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
47
lib/fog/aws/requests/iam/list_user_policies.rb
Normal file
47
lib/fog/aws/requests/iam/list_user_policies.rb
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class IAM
|
||||||
|
class Real
|
||||||
|
|
||||||
|
require 'fog/aws/parsers/iam/list_policies'
|
||||||
|
|
||||||
|
# List policies for a user
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * user_name<~String> - Name of user to list policies for
|
||||||
|
# * options<~Hash>: Optional
|
||||||
|
# * 'Marker'<~String>: used to paginate subsequent requests
|
||||||
|
# * 'MaxItems'<~Integer>: limit results to this number per page
|
||||||
|
# * 'PathPrefix'<~String>: prefix for filtering results
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'PolicyNames'<~Array> - Matching policy names
|
||||||
|
# * 'IsTruncated<~Boolean> - Whether or not results were truncated
|
||||||
|
# * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use
|
||||||
|
# * 'RequestId'<~String> - Id of the request
|
||||||
|
#
|
||||||
|
# ==== See Also
|
||||||
|
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListUserPolicies.html
|
||||||
|
#
|
||||||
|
def list_user_policies(user_name, options = {})
|
||||||
|
request({
|
||||||
|
'Action' => 'ListUserPolicies',
|
||||||
|
'UserName' => user_name,
|
||||||
|
:parser => Fog::Parsers::AWS::IAM::ListPolicies.new
|
||||||
|
}.merge!(options))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def list_user_policies(user_name, options = {})
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
44
lib/fog/aws/requests/iam/put_user_policy.rb
Normal file
44
lib/fog/aws/requests/iam/put_user_policy.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class IAM
|
||||||
|
class Real
|
||||||
|
|
||||||
|
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
|
||||||
|
# * policy_document<~Hash>: policy document, see: http://docs.amazonwebservices.com/IAM/latest/UserGuide/PoliciesOverview.html
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'RequestId'<~String> - Id of the request
|
||||||
|
#
|
||||||
|
# ==== See Also
|
||||||
|
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_PutUserPolicy.html
|
||||||
|
#
|
||||||
|
def put_user_policy(user_name, policy_name, policy_document)
|
||||||
|
request(
|
||||||
|
'Action' => 'PutUserPolicy',
|
||||||
|
'PolicyName' => policy_name,
|
||||||
|
'PolicyDocument' => policy_document.to_json,
|
||||||
|
'UserName' => user_name,
|
||||||
|
:parser => Fog::Parsers::AWS::IAM::Basic.new
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def put_user_policy(user_name, policy_name, policy_document)
|
||||||
|
Fog::Mock.not_implemented
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
35
tests/aws/requests/iam/user_policy_tests.rb
Normal file
35
tests/aws/requests/iam/user_policy_tests.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
Shindo.tests('AWS::IAM | user policy requests', ['aws']) do
|
||||||
|
|
||||||
|
AWS[:iam].create_user('fog_user_policy_tests')
|
||||||
|
|
||||||
|
tests('success') do
|
||||||
|
|
||||||
|
@policy = {"Statement" => [{"Effect" => "Allow", "Action" => "*", "Resource" => "*"}]}
|
||||||
|
|
||||||
|
tests("#put_user_policy('fog_user_policy_tests', 'fog_policy', #{@policy.inspect})").formats(AWS::IAM::Formats::BASIC) do
|
||||||
|
AWS[:iam].put_user_policy('fog_user_policy_tests', 'fog_policy', @policy).body
|
||||||
|
end
|
||||||
|
|
||||||
|
@user_policies_format = {
|
||||||
|
'IsTruncated' => Fog::Boolean,
|
||||||
|
'PolicyNames' => [String],
|
||||||
|
'RequestId' => String
|
||||||
|
}
|
||||||
|
|
||||||
|
tests("list_user_policies('fog_user_policy_tests')").formats(@user_policies_format) do
|
||||||
|
AWS[:iam].list_user_policies('fog_user_policy_tests').body
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#delete_user_policy('fog_user_policy_tests', 'fog_policy')").formats(AWS::IAM::Formats::BASIC) do
|
||||||
|
AWS[:iam].delete_user_policy('fog_user_policy_tests', 'fog_policy').body
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('failure') do
|
||||||
|
test('failing conditions')
|
||||||
|
end
|
||||||
|
|
||||||
|
AWS[:iam].delete_user('fog_user_policy_tests')
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue