mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|iam] fleshing out iam requests/tests
This commit is contained in:
parent
73d85415be
commit
04893cf1b5
18 changed files with 383 additions and 27 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'requestId'
|
||||
when 'RequestId'
|
||||
@response[name] = @value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
32
lib/fog/aws/parsers/iam/list_access_keys.rb
Normal file
32
lib/fog/aws/parsers/iam/list_access_keys.rb
Normal file
|
@ -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
|
|
@ -3,7 +3,7 @@ module Fog
|
|||
module AWS
|
||||
module IAM
|
||||
|
||||
class ListGroups < Fog::Parsers::Base
|
||||
class ListGroupPolicies < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'PolicyNames' => [] }
|
||||
|
|
32
lib/fog/aws/parsers/iam/list_users.rb
Normal file
32
lib/fog/aws/parsers/iam/list_users.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
48
lib/fog/aws/requests/iam/list_access_keys.rb
Normal file
48
lib/fog/aws/requests/iam/list_access_keys.rb
Normal file
|
@ -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
|
50
lib/fog/aws/requests/iam/list_users.rb
Normal file
50
lib/fog/aws/requests/iam/list_users.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -13,6 +13,18 @@ class AWS
|
|||
|
||||
end
|
||||
|
||||
module IAM
|
||||
|
||||
module Formats
|
||||
|
||||
BASIC = {
|
||||
'RequestId' => String
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
unless defined?(GENTOO_AMI)
|
||||
|
|
48
tests/aws/requests/iam/access_key_tests.rb
Normal file
48
tests/aws/requests/iam/access_key_tests.rb
Normal file
|
@ -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
|
35
tests/aws/requests/iam/group_policy_tests.rb
Normal file
35
tests/aws/requests/iam/group_policy_tests.rb
Normal file
|
@ -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
|
47
tests/aws/requests/iam/group_tests.rb
Normal file
47
tests/aws/requests/iam/group_tests.rb
Normal file
|
@ -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
|
56
tests/aws/requests/iam/user_tests.rb
Normal file
56
tests/aws/requests/iam/user_tests.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue