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|
|
@data ||= Hash.new do |hash, key|
|
||||||
hash[key] = {
|
hash[key] = {
|
||||||
:owner_id => Fog::AWS::Mock.owner_id,
|
: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
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,20 +36,18 @@ module Fog
|
||||||
def create_access_key(options)
|
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
|
#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
|
# Also doesn't raise an error when there are too many keys
|
||||||
data[:users] ||= {}
|
|
||||||
user_name = options['UserName']
|
user_name = options['UserName']
|
||||||
if data[:users].keys.include? user_name
|
if data[:users].keys.include? user_name
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
user_resp = { 'AccessKey' => { 'SecretAccessKey' => '',
|
key = { 'SecretAccessKey' => '123',
|
||||||
'Status' => 'Active',
|
'Status' => 'Active',
|
||||||
'AccessKeyId' => '',
|
'AccessKeyId' => '456',
|
||||||
'UserName' => user_name
|
'UserName' => user_name
|
||||||
},
|
}
|
||||||
'RequestId' => Fog::AWS::Mock.request_id }
|
data[:users][user_name][:access_keys] << key
|
||||||
data[:users][user_name][:access_keys] ||= []
|
|
||||||
data[:users][user_name][:access_keys] << user_resp
|
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = user_resp
|
response.body = { 'AccessKey' => key,
|
||||||
|
'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
response
|
response
|
||||||
else
|
else
|
||||||
raise Fog::AWS::IAM::NotFound.new('The user with name booboboboob cannot be found.')
|
raise Fog::AWS::IAM::NotFound.new('The user with name booboboboob cannot be found.')
|
||||||
|
|
|
@ -37,23 +37,22 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def create_user(user_name, path='/')
|
def create_user(user_name, path='/')
|
||||||
data[:users] ||= {}
|
|
||||||
if data[:users].keys.include? user_name
|
if data[:users].keys.include? user_name
|
||||||
raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
|
raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
|
||||||
else
|
else
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
user_resp = { "User" => {
|
data[:users][user_name][:path] = path
|
||||||
"UserId" => Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 21),
|
user = {
|
||||||
"Path" => path,
|
"UserId" => data[:users][user_name][:user_id],
|
||||||
|
"Path" => data[:users][user_name][:path],
|
||||||
"UserName" => user_name,
|
"UserName" => user_name,
|
||||||
"Arn" => "arn:aws:iam::#{Fog::AWS::Mock.owner_id}:user/#{user_name}"
|
"Arn" => data[:users][user_name][:arn]
|
||||||
},
|
|
||||||
"RequestId" => Fog::AWS::Mock.request_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data[:users][user_name] = user_resp
|
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = user_resp
|
response.body = { 'User' => user,
|
||||||
|
'RequestId' => Fog::AWS::Mock.request_id
|
||||||
|
}
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue