From c83e1bae007dae91951e1c1992f500fdb2c5563c Mon Sep 17 00:00:00 2001 From: geemus Date: Wed, 17 Nov 2010 12:04:49 -0800 Subject: [PATCH] [aws|iam] user policy requests/tests --- lib/fog/aws/iam.rb | 3 ++ ...ist_group_policies.rb => list_policies.rb} | 2 +- .../aws/requests/iam/delete_user_policy.rb | 42 +++++++++++++++++ .../aws/requests/iam/list_group_policies.rb | 4 +- .../aws/requests/iam/list_user_policies.rb | 47 +++++++++++++++++++ lib/fog/aws/requests/iam/put_user_policy.rb | 44 +++++++++++++++++ tests/aws/requests/iam/user_policy_tests.rb | 35 ++++++++++++++ 7 files changed, 174 insertions(+), 3 deletions(-) rename lib/fog/aws/parsers/iam/{list_group_policies.rb => list_policies.rb} (90%) create mode 100644 lib/fog/aws/requests/iam/delete_user_policy.rb create mode 100644 lib/fog/aws/requests/iam/list_user_policies.rb create mode 100644 lib/fog/aws/requests/iam/put_user_policy.rb create mode 100644 tests/aws/requests/iam/user_policy_tests.rb diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 8a251bda0..43c02515a 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -13,11 +13,14 @@ module Fog request :delete_group request :delete_group_policy request :delete_user + request :delete_user_policy request :list_access_keys request :list_groups request :list_group_policies + request :list_user_policies request :list_users request :put_group_policy + request :put_user_policy request :remove_user_from_group class Mock diff --git a/lib/fog/aws/parsers/iam/list_group_policies.rb b/lib/fog/aws/parsers/iam/list_policies.rb similarity index 90% rename from lib/fog/aws/parsers/iam/list_group_policies.rb rename to lib/fog/aws/parsers/iam/list_policies.rb index af5c93467..3a6d1ab4a 100644 --- a/lib/fog/aws/parsers/iam/list_group_policies.rb +++ b/lib/fog/aws/parsers/iam/list_policies.rb @@ -3,7 +3,7 @@ module Fog module AWS module IAM - class ListGroupPolicies < Fog::Parsers::Base + class ListPolicies < Fog::Parsers::Base def reset @response = { 'PolicyNames' => [] } diff --git a/lib/fog/aws/requests/iam/delete_user_policy.rb b/lib/fog/aws/requests/iam/delete_user_policy.rb new file mode 100644 index 000000000..eb447b07a --- /dev/null +++ b/lib/fog/aws/requests/iam/delete_user_policy.rb @@ -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 diff --git a/lib/fog/aws/requests/iam/list_group_policies.rb b/lib/fog/aws/requests/iam/list_group_policies.rb index 01ec4eb70..cd06643ff 100644 --- a/lib/fog/aws/requests/iam/list_group_policies.rb +++ b/lib/fog/aws/requests/iam/list_group_policies.rb @@ -3,7 +3,7 @@ module Fog class IAM class Real - require 'fog/aws/parsers/iam/list_group_policies' + require 'fog/aws/parsers/iam/list_policies' # List policies for a group # @@ -29,7 +29,7 @@ module Fog request({ 'Action' => 'ListGroupPolicies', 'GroupName' => group_name, - :parser => Fog::Parsers::AWS::IAM::ListGroupPolicies.new + :parser => Fog::Parsers::AWS::IAM::ListPolicies.new }.merge!(options)) end diff --git a/lib/fog/aws/requests/iam/list_user_policies.rb b/lib/fog/aws/requests/iam/list_user_policies.rb new file mode 100644 index 000000000..e0b7528bf --- /dev/null +++ b/lib/fog/aws/requests/iam/list_user_policies.rb @@ -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 diff --git a/lib/fog/aws/requests/iam/put_user_policy.rb b/lib/fog/aws/requests/iam/put_user_policy.rb new file mode 100644 index 000000000..c2d6ee307 --- /dev/null +++ b/lib/fog/aws/requests/iam/put_user_policy.rb @@ -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 diff --git a/tests/aws/requests/iam/user_policy_tests.rb b/tests/aws/requests/iam/user_policy_tests.rb new file mode 100644 index 000000000..e38a953ad --- /dev/null +++ b/tests/aws/requests/iam/user_policy_tests.rb @@ -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 \ No newline at end of file