diff --git a/lib/fog/aws/iam.rb b/lib/fog/aws/iam.rb index 95000ba61..8a251bda0 100644 --- a/lib/fog/aws/iam.rb +++ b/lib/fog/aws/iam.rb @@ -13,8 +13,10 @@ module Fog request :delete_group request :delete_group_policy request :delete_user + request :list_access_keys request :list_groups request :list_group_policies + request :list_users request :put_group_policy request :remove_user_from_group diff --git a/lib/fog/aws/parsers/iam/basic.rb b/lib/fog/aws/parsers/iam/basic.rb index ec9c6a590..10bf5da63 100644 --- a/lib/fog/aws/parsers/iam/basic.rb +++ b/lib/fog/aws/parsers/iam/basic.rb @@ -7,7 +7,7 @@ module Fog def end_element(name) case name - when 'requestId' + when 'RequestId' @response[name] = @value end end diff --git a/lib/fog/aws/parsers/iam/create_access_key.rb b/lib/fog/aws/parsers/iam/create_access_key.rb index f77d6abe2..f0559ef30 100644 --- a/lib/fog/aws/parsers/iam/create_access_key.rb +++ b/lib/fog/aws/parsers/iam/create_access_key.rb @@ -11,8 +11,8 @@ module Fog def end_element(name) case name - when 'AccessKey', 'UserName', 'SecretAccessKey', 'Status' - @response['User'][name] = @value + when 'AccessKeyId', 'UserName', 'SecretAccessKey', 'Status' + @response['AccessKey'][name] = @value when 'RequestId' @response[name] = @value end diff --git a/lib/fog/aws/parsers/iam/list_access_keys.rb b/lib/fog/aws/parsers/iam/list_access_keys.rb new file mode 100644 index 000000000..2237d9733 --- /dev/null +++ b/lib/fog/aws/parsers/iam/list_access_keys.rb @@ -0,0 +1,32 @@ +module Fog + module Parsers + module AWS + module IAM + + class ListAccessKeys < Fog::Parsers::Base + + def reset + @access_key = {} + @response = { 'AccessKeys' => [] } + end + + def end_element(name) + case name + when 'AccessKeyId', 'Status', 'Username' + @access_key[name] = @value + when 'member' + @response['AccessKeys'] << @access_key + @access_key = {} + when 'IsTruncated' + response[name] = (@value == 'true') + when 'Marker', 'RequestId' + response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/parsers/iam/list_group_policies.rb b/lib/fog/aws/parsers/iam/list_group_policies.rb index 5fb743626..af5c93467 100644 --- a/lib/fog/aws/parsers/iam/list_group_policies.rb +++ b/lib/fog/aws/parsers/iam/list_group_policies.rb @@ -3,7 +3,7 @@ module Fog module AWS module IAM - class ListGroups < Fog::Parsers::Base + class ListGroupPolicies < Fog::Parsers::Base def reset @response = { 'PolicyNames' => [] } diff --git a/lib/fog/aws/parsers/iam/list_users.rb b/lib/fog/aws/parsers/iam/list_users.rb new file mode 100644 index 000000000..7e83d6a43 --- /dev/null +++ b/lib/fog/aws/parsers/iam/list_users.rb @@ -0,0 +1,32 @@ +module Fog + module Parsers + module AWS + module IAM + + class ListUsers < Fog::Parsers::Base + + def reset + @user = {} + @response = { 'Users' => [] } + end + + def end_element(name) + case name + when 'Arn', 'UserId', 'UserName', 'Path' + @user[name] = @value + when 'member' + @response['Users'] << @user + @user = {} + when 'IsTruncated' + response[name] = (@value == 'true') + when 'Marker', 'RequestId' + response[name] = @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/create_access_key.rb b/lib/fog/aws/requests/iam/create_access_key.rb index 73e84ebb4..cc4ad30ae 100644 --- a/lib/fog/aws/requests/iam/create_access_key.rb +++ b/lib/fog/aws/requests/iam/create_access_key.rb @@ -8,13 +8,14 @@ module Fog # Create a access keys for user (by default detects user from access credentials) # # ==== Parameters - # * user_name<~String> - optional: name of the user to create (do not include path) + # * options<~Hash>: + # * 'UserName'<~String> - name of the user to create (do not include path) # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: - # * 'User'<~Hash>: - # * 'AccessKey'<~String> - + # * 'AccessKey'<~Hash>: + # * 'AccessKeyId'<~String> - # * 'Username'<~String> - # * 'SecretAccessKey'<~String> - # * 'Status'<~String> - @@ -23,15 +24,11 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateAccessKey.html # - def create_access_key(user_name = nil) - params = { + def create_access_key(options = {}) + request({ 'Action' => 'CreateAccessKey', :parser => Fog::Parsers::AWS::IAM::CreateAccessKey.new - } - if user_name - params['UserName'] = user_name - end - request(params) + }.merge!(options)) end end diff --git a/lib/fog/aws/requests/iam/create_user.rb b/lib/fog/aws/requests/iam/create_user.rb index 1c5d90835..099171c4e 100644 --- a/lib/fog/aws/requests/iam/create_user.rb +++ b/lib/fog/aws/requests/iam/create_user.rb @@ -16,9 +16,9 @@ module Fog # * body<~Hash>: # * 'User'<~Hash>: # * 'Arn'<~String> - - # * 'GroupId'<~String> - - # * 'GroupName'<~String> - # * 'Path'<~String> - + # * 'UserId'<~String> - + # * 'UserName'<~String> - # * 'RequestId'<~String> - Id of the request # # ==== See Also diff --git a/lib/fog/aws/requests/iam/delete_access_key.rb b/lib/fog/aws/requests/iam/delete_access_key.rb index ff52ced1d..f7e7a2d17 100644 --- a/lib/fog/aws/requests/iam/delete_access_key.rb +++ b/lib/fog/aws/requests/iam/delete_access_key.rb @@ -9,7 +9,8 @@ module Fog # # ==== Parameters # * access_key_id<~String> - Access key id to delete - # * user_name<~String> - optional: name of the user to delete access key from + # * options<~Hash>: + # * 'UserName'<~String> - name of the user to create (do not include path) # # ==== Returns # * response<~Excon::Response>: @@ -19,16 +20,12 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteAccessKey.html # - def delete_access_key(access_key_id, user_name = nil) - params = { + def delete_access_key(access_key_id, options = {}) + request({ 'AccessKeyId' => access_key_id, - 'Action' => 'DeleteUser', + 'Action' => 'DeleteAccessKey', :parser => Fog::Parsers::AWS::IAM::Basic.new - } - if user_name - params['UserName'] = user_name - end - request(params) + }.merge!(options)) end end diff --git a/lib/fog/aws/requests/iam/delete_group_policy.rb b/lib/fog/aws/requests/iam/delete_group_policy.rb index a08690132..ef5f5341f 100644 --- a/lib/fog/aws/requests/iam/delete_group_policy.rb +++ b/lib/fog/aws/requests/iam/delete_group_policy.rb @@ -14,7 +14,7 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: - # * 'RequestId'<~String> - Id of the request def put_group_policy(group_name, path = '/') + # * 'RequestId'<~String> - Id of the request # # ==== See Also # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_DeleteGroupPolicy.html diff --git a/lib/fog/aws/requests/iam/list_access_keys.rb b/lib/fog/aws/requests/iam/list_access_keys.rb new file mode 100644 index 000000000..ccf8fb06d --- /dev/null +++ b/lib/fog/aws/requests/iam/list_access_keys.rb @@ -0,0 +1,48 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/list_access_keys' + + # List access_keys + # + # ==== Parameters + # * options<~Hash>: + # * 'Marker'<~String> - used to paginate subsequent requests + # * 'MaxItems'<~Integer> - limit results to this number per page + # * 'UserName'<~String> - optional: username to lookup access keys for, defaults to current user + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'AccessKeys'<~Array> - Matching access keys + # * access_key<~Hash>: + # * AccessKeyId<~String> - + # * Status<~String> - + # * '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_ListAccessKeys.html + # + def list_access_keys(options = {}) + request({ + 'Action' => 'ListAccessKeys', + :parser => Fog::Parsers::AWS::IAM::ListAccessKeys.new + }.merge!(options)) + end + + end + + class Mock + + def list_access_keys(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/list_users.rb b/lib/fog/aws/requests/iam/list_users.rb new file mode 100644 index 000000000..24dd7ea14 --- /dev/null +++ b/lib/fog/aws/requests/iam/list_users.rb @@ -0,0 +1,50 @@ +module Fog + module AWS + class IAM + class Real + + require 'fog/aws/parsers/iam/list_users' + + # List users + # + # ==== Parameters + # * options<~Hash>: + # * '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>: + # * 'Users'<~Array> - Matching groups + # * user<~Hash>: + # * Arn<~String> - + # * Path<~String> - + # * UserId<~String> - + # * UserName<~String> - + # * '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_ListUsers.html + # + def list_users(options = {}) + request({ + 'Action' => 'ListUsers', + :parser => Fog::Parsers::AWS::IAM::ListUsers.new + }.merge!(options)) + end + + end + + class Mock + + def list_users(options = {}) + Fog::Mock.not_implemented + end + + end + end + end +end diff --git a/lib/fog/aws/requests/iam/put_group_policy.rb b/lib/fog/aws/requests/iam/put_group_policy.rb index d1957b344..c2abdd489 100644 --- a/lib/fog/aws/requests/iam/put_group_policy.rb +++ b/lib/fog/aws/requests/iam/put_group_policy.rb @@ -15,7 +15,7 @@ module Fog # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: - # * 'RequestId'<~String> - Id of the request def put_group_policy(group_name, path = '/') + # * 'RequestId'<~String> - Id of the request # # ==== See Also # http://docs.amazonwebservices.com/IAM/latest/APIReference/API_PutGroupPolicy.html diff --git a/tests/aws/helper.rb b/tests/aws/helper.rb index c2ca70164..ed73c0106 100644 --- a/tests/aws/helper.rb +++ b/tests/aws/helper.rb @@ -13,6 +13,18 @@ class AWS end + module IAM + + module Formats + + BASIC = { + 'RequestId' => String + } + + end + + end + end unless defined?(GENTOO_AMI) diff --git a/tests/aws/requests/iam/access_key_tests.rb b/tests/aws/requests/iam/access_key_tests.rb new file mode 100644 index 000000000..2c3370e81 --- /dev/null +++ b/tests/aws/requests/iam/access_key_tests.rb @@ -0,0 +1,48 @@ +Shindo.tests('AWS::IAM | access key requests', ['aws']) do + + AWS[:iam].create_user('fog_access_key_tests') + + tests('success') do + + @access_key_format = { + 'AccessKey' => { + 'AccessKeyId' => String, + 'UserName' => String, + 'SecretAccessKey' => String, + 'Status' => String + }, + 'RequestId' => String + } + + tests("#create_access_key('UserName' => 'fog_access_key_tests')").formats(@access_key_format) do + data = AWS[:iam].create_access_key('UserName' => 'fog_access_key_tests').body + @access_key_id = data['AccessKey']['AccessKeyId'] + data + end + + @access_keys_format = { + 'AccessKeys' => [{ + 'AccessKeyId' => String, + 'Status' => String + }], + 'IsTruncated' => Fog::Boolean, + 'RequestId' => String + } + + tests("#list_access_keys('Username' => 'fog_access_key_tests')").formats(@access_keys_format) do + AWS[:iam].list_access_keys('UserName' => 'fog_access_key_tests').body + end + + tests("#delete_access_key('#{@access_key_id}', 'UserName' => 'fog_access_key_tests)").formats(AWS::IAM::Formats::BASIC) do + AWS[:iam].delete_access_key(@access_key_id, 'UserName' => 'fog_access_key_tests').body + end + + end + + tests('failure') do + test('failing conditions') + end + + AWS[:iam].delete_user('fog_access_key_tests') + +end \ No newline at end of file diff --git a/tests/aws/requests/iam/group_policy_tests.rb b/tests/aws/requests/iam/group_policy_tests.rb new file mode 100644 index 000000000..549e6091b --- /dev/null +++ b/tests/aws/requests/iam/group_policy_tests.rb @@ -0,0 +1,35 @@ +Shindo.tests('AWS::IAM | group policy requests', ['aws']) do + + 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 + AWS[:iam].put_group_policy('fog_group_policy_tests', 'fog_policy', @policy).body + end + + @group_policies_format = { + 'IsTruncated' => Fog::Boolean, + 'PolicyNames' => [String], + 'RequestId' => String + } + + tests("list_group_policies('fog_group_policy_tests')").formats(@group_policies_format) do + AWS[:iam].list_group_policies('fog_group_policy_tests').body + end + + tests("#delete_group_policy('fog_group_policy_tests', 'fog_policy')").formats(AWS::IAM::Formats::BASIC) do + AWS[:iam].delete_group_policy('fog_group_policy_tests', 'fog_policy').body + end + + end + + tests('failure') do + test('failing conditions') + end + + AWS[:iam].delete_group('fog_group_policy_tests') + +end \ No newline at end of file diff --git a/tests/aws/requests/iam/group_tests.rb b/tests/aws/requests/iam/group_tests.rb new file mode 100644 index 000000000..9fda64536 --- /dev/null +++ b/tests/aws/requests/iam/group_tests.rb @@ -0,0 +1,47 @@ +Shindo.tests('AWS::IAM | group requests', ['aws']) do + + tests('success') do + + @group_format = { + 'Group' => { + 'Arn' => String, + 'GroupId' => String, + 'GroupName' => String, + 'Path' => String + }, + 'RequestId' => String + } + + tests("#create_group('fog_group')").formats(@group_format) do + pending if Fog.mocking? + AWS[:iam].create_group('fog_group').body + end + + @groups_format = { + 'Groups' => [{ + 'Arn' => String, + 'GroupId' => String, + 'GroupName' => String, + 'Path' => String + }], + 'IsTruncated' => Fog::Boolean, + 'RequestId' => String + } + + tests("#list_groups").formats(@groups_format) do + pending if Fog.mocking? + AWS[:iam].list_groups.body + end + + tests("#delete_group('fog_group')").formats(AWS::IAM::Formats::BASIC) do + pending if Fog.mocking? + AWS[:iam].delete_group('fog_group').body + end + + end + + tests('failure') do + test('failing conditions') + end + +end \ No newline at end of file diff --git a/tests/aws/requests/iam/user_tests.rb b/tests/aws/requests/iam/user_tests.rb new file mode 100644 index 000000000..3cf8f81a8 --- /dev/null +++ b/tests/aws/requests/iam/user_tests.rb @@ -0,0 +1,56 @@ +Shindo.tests('AWS::IAM | user requests', ['aws']) do + + AWS[:iam].create_group('fog_user_tests') + + tests('success') do + + @user_format = { + 'User' => { + 'Arn' => String, + 'Path' => String, + 'UserId' => String, + 'UserName' => String + }, + 'RequestId' => String + } + + tests("#create_user('fog_user')").formats(@user_format) do + AWS[:iam].create_user('fog_user').body + end + + @users_format = { + 'Users' => [{ + 'Arn' => String, + 'Path' => String, + 'UserId' => String, + 'UserName' => String + }], + 'IsTruncated' => Fog::Boolean, + 'RequestId' => String + } + + tests("#list_users").formats(@users_format) do + AWS[:iam].list_users.body + end + + tests("#add_user_to_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do + AWS[:iam].add_user_to_group('fog_user_tests', 'fog_user').body + end + + tests("#remove_user_from_group('fog_user_tests', 'fog_user')").formats(AWS::IAM::Formats::BASIC) do + AWS[:iam].remove_user_from_group('fog_user_tests', 'fog_user').body + end + + tests("#delete_user('fog_user')").formats(AWS::IAM::Formats::BASIC) do + AWS[:iam].delete_user('fog_user').body + end + + end + + tests('failure') do + test('failing conditions') + end + + AWS[:iam].delete_group('fog_user_tests') + +end \ No newline at end of file