mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
rework these to use #tap instead. Cleaner IMNSHO
This commit is contained in:
parent
3469dbaf3f
commit
5171df8ede
5 changed files with 44 additions and 43 deletions
|
@ -37,18 +37,20 @@ module Fog
|
|||
#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
|
||||
user_name = options['UserName']
|
||||
if data[:users].keys.include? user_name
|
||||
response = Excon::Response.new
|
||||
key = { 'SecretAccessKey' => '123',
|
||||
if data[:users].has_key? user_name
|
||||
key = { 'SecretAccessKey' => Fog::Mock.random_base64(40),
|
||||
'Status' => 'Active',
|
||||
'AccessKeyId' => '456',
|
||||
'AccessKeyId' => Fog::AWS::Mock.key_id(20),
|
||||
'UserName' => user_name
|
||||
}
|
||||
|
||||
data[:users][user_name][:access_keys] << key
|
||||
response.status = 200
|
||||
response.body = { 'AccessKey' => key,
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response
|
||||
|
||||
Excon::Response.new.tap do |response|
|
||||
response.status = 200
|
||||
response.body = { 'AccessKey' => key,
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
end
|
||||
else
|
||||
raise Fog::AWS::IAM::NotFound.new('The user with name booboboboob cannot be found.')
|
||||
end
|
||||
|
|
|
@ -37,23 +37,21 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_user(user_name, path='/')
|
||||
if data[:users].keys.include? user_name
|
||||
if data[:users].has_key? user_name
|
||||
raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
|
||||
else
|
||||
response = Excon::Response.new
|
||||
data[:users][user_name][:path] = path
|
||||
user = {
|
||||
"UserId" => data[:users][user_name][:user_id],
|
||||
"Path" => data[:users][user_name][:path],
|
||||
"UserName" => user_name,
|
||||
"Arn" => data[:users][user_name][:arn]
|
||||
}
|
||||
|
||||
response.status = 200
|
||||
response.body = { 'User' => user,
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
response
|
||||
Excon::Response.new.tap do |response|
|
||||
response.status = 200
|
||||
response.body = { 'User' => {
|
||||
"UserId" => data[:users][user_name][:user_id],
|
||||
"Path" => path,
|
||||
"UserName" => user_name,
|
||||
"Arn" => data[:users][user_name][:arn]
|
||||
},
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,12 +33,12 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def delete_user_policy(user_name, policy_name)
|
||||
if data[:users].keys.include?(user_name) && data[:users][user_name][:policies].keys.include?(policy_name)
|
||||
if data[:users].has_key?(user_name) && data[:users][user_name][:policies].has_key?(policy_name)
|
||||
data[:users][user_name][:policies].delete policy_name
|
||||
response = Excon::Response.new
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
response
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
else
|
||||
raise Fog::AWS::IAM::NotFound.new("The user policy with name #{policy_name} cannot be found.")
|
||||
end
|
||||
|
|
|
@ -41,17 +41,17 @@ module Fog
|
|||
class Mock
|
||||
def list_users(options = {})
|
||||
#FIXME: none of the options are currently supported
|
||||
response = Excon::Response.new
|
||||
response.body = {'Users' => data[:users].map do |user, data|
|
||||
{ 'UserId' => data[:user_id],
|
||||
'Path' => data[:path],
|
||||
'UserName' => user,
|
||||
'Arn' => data[:arn] }
|
||||
end,
|
||||
'IsTruncated' => false,
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
response
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = {'Users' => data[:users].map do |user, data|
|
||||
{ 'UserId' => data[:user_id],
|
||||
'Path' => data[:path],
|
||||
'UserName' => user,
|
||||
'Arn' => data[:arn] }
|
||||
end,
|
||||
'IsTruncated' => false,
|
||||
'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,12 +37,13 @@ module Fog
|
|||
#FIXME: You can't actually use the credentials for anything elsewhere in Fog
|
||||
#FIXME: Doesn't do any validation on the policy
|
||||
def put_user_policy(user_name, policy_name, policy_document)
|
||||
if data[:users].keys.include? user_name
|
||||
response = Excon::Response.new
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
if data[:users].has_key? user_name
|
||||
data[:users][user_name][:policies][policy_name] = policy_document
|
||||
response
|
||||
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
else
|
||||
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue