mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Refactor mock data structure
This commit is contained in:
parent
7b5602c758
commit
d353165a68
3 changed files with 28 additions and 22 deletions
|
@ -61,7 +61,16 @@ module Fog
|
|||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:owner_id => Fog::AWS::Mock.owner_id,
|
||||
:server_certificates => {}
|
||||
:server_certificates => {},
|
||||
:users => Hash.new do |uhash, ukey|
|
||||
uhash[ukey] = {
|
||||
:user_id => Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 21),
|
||||
:path => '/',
|
||||
:arn => "arn:aws:iam::#{Fog::AWS::Mock.owner_id}:user/#{ukey}",
|
||||
:access_keys => [],
|
||||
:policies => {}
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,20 +36,18 @@ module Fog
|
|||
def create_access_key(options)
|
||||
#FIXME: Not 100% correct as AWS will use the signing credentials when there is no 'UserName' in the options hash
|
||||
# Also doesn't raise an error when there are too many keys
|
||||
data[:users] ||= {}
|
||||
user_name = options['UserName']
|
||||
if data[:users].keys.include? user_name
|
||||
response = Excon::Response.new
|
||||
user_resp = { 'AccessKey' => { 'SecretAccessKey' => '',
|
||||
key = { 'SecretAccessKey' => '123',
|
||||
'Status' => 'Active',
|
||||
'AccessKeyId' => '',
|
||||
'AccessKeyId' => '456',
|
||||
'UserName' => user_name
|
||||
},
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
data[:users][user_name][:access_keys] ||= []
|
||||
data[:users][user_name][:access_keys] << user_resp
|
||||
}
|
||||
data[:users][user_name][:access_keys] << key
|
||||
response.status = 200
|
||||
response.body = user_resp
|
||||
response.body = { 'AccessKey' => key,
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response
|
||||
else
|
||||
raise Fog::AWS::IAM::NotFound.new('The user with name booboboboob cannot be found.')
|
||||
|
|
|
@ -37,23 +37,22 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_user(user_name, path='/')
|
||||
data[:users] ||= {}
|
||||
if data[:users].keys.include? user_name
|
||||
raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
|
||||
else
|
||||
response = Excon::Response.new
|
||||
user_resp = { "User" => {
|
||||
"UserId" => Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 21),
|
||||
"Path" => path,
|
||||
data[:users][user_name][:path] = path
|
||||
user = {
|
||||
"UserId" => data[:users][user_name][:user_id],
|
||||
"Path" => data[:users][user_name][:path],
|
||||
"UserName" => user_name,
|
||||
"Arn" => "arn:aws:iam::#{Fog::AWS::Mock.owner_id}:user/#{user_name}"
|
||||
},
|
||||
"RequestId" => Fog::AWS::Mock.request_id
|
||||
"Arn" => data[:users][user_name][:arn]
|
||||
}
|
||||
|
||||
data[:users][user_name] = user_resp
|
||||
response.status = 200
|
||||
response.body = user_resp
|
||||
response.body = { 'User' => user,
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue