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
|
#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
|
||||||
user_name = options['UserName']
|
user_name = options['UserName']
|
||||||
if data[:users].keys.include? user_name
|
if data[:users].has_key? user_name
|
||||||
response = Excon::Response.new
|
key = { 'SecretAccessKey' => Fog::Mock.random_base64(40),
|
||||||
key = { 'SecretAccessKey' => '123',
|
|
||||||
'Status' => 'Active',
|
'Status' => 'Active',
|
||||||
'AccessKeyId' => '456',
|
'AccessKeyId' => Fog::AWS::Mock.key_id(20),
|
||||||
'UserName' => user_name
|
'UserName' => user_name
|
||||||
}
|
}
|
||||||
|
|
||||||
data[:users][user_name][:access_keys] << key
|
data[:users][user_name][:access_keys] << key
|
||||||
response.status = 200
|
|
||||||
response.body = { 'AccessKey' => key,
|
Excon::Response.new.tap do |response|
|
||||||
'RequestId' => Fog::AWS::Mock.request_id }
|
response.status = 200
|
||||||
response
|
response.body = { 'AccessKey' => key,
|
||||||
|
'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
end
|
||||||
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.')
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,23 +37,21 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
def create_user(user_name, path='/')
|
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."
|
raise Fog::AWS::IAM::EntityAlreadyExists.new "User with name #{user_name} already exists."
|
||||||
else
|
else
|
||||||
response = Excon::Response.new
|
|
||||||
data[:users][user_name][:path] = path
|
data[:users][user_name][:path] = path
|
||||||
user = {
|
Excon::Response.new.tap do |response|
|
||||||
"UserId" => data[:users][user_name][:user_id],
|
response.status = 200
|
||||||
"Path" => data[:users][user_name][:path],
|
response.body = { 'User' => {
|
||||||
"UserName" => user_name,
|
"UserId" => data[:users][user_name][:user_id],
|
||||||
"Arn" => data[:users][user_name][:arn]
|
"Path" => path,
|
||||||
}
|
"UserName" => user_name,
|
||||||
|
"Arn" => data[:users][user_name][:arn]
|
||||||
response.status = 200
|
},
|
||||||
response.body = { 'User' => user,
|
'RequestId' => Fog::AWS::Mock.request_id
|
||||||
'RequestId' => Fog::AWS::Mock.request_id
|
}
|
||||||
}
|
end
|
||||||
response
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,12 +33,12 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def delete_user_policy(user_name, policy_name)
|
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
|
data[:users][user_name][:policies].delete policy_name
|
||||||
response = Excon::Response.new
|
Excon::Response.new.tap do |response|
|
||||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response
|
end
|
||||||
else
|
else
|
||||||
raise Fog::AWS::IAM::NotFound.new("The user policy with name #{policy_name} cannot be found.")
|
raise Fog::AWS::IAM::NotFound.new("The user policy with name #{policy_name} cannot be found.")
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,17 +41,17 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
def list_users(options = {})
|
def list_users(options = {})
|
||||||
#FIXME: none of the options are currently supported
|
#FIXME: none of the options are currently supported
|
||||||
response = Excon::Response.new
|
Excon::Response.new.tap do |response|
|
||||||
response.body = {'Users' => data[:users].map do |user, data|
|
response.body = {'Users' => data[:users].map do |user, data|
|
||||||
{ 'UserId' => data[:user_id],
|
{ 'UserId' => data[:user_id],
|
||||||
'Path' => data[:path],
|
'Path' => data[:path],
|
||||||
'UserName' => user,
|
'UserName' => user,
|
||||||
'Arn' => data[:arn] }
|
'Arn' => data[:arn] }
|
||||||
end,
|
end,
|
||||||
'IsTruncated' => false,
|
'IsTruncated' => false,
|
||||||
'RequestId' => Fog::AWS::Mock.request_id }
|
'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,12 +37,13 @@ module Fog
|
||||||
#FIXME: You can't actually use the credentials for anything elsewhere in Fog
|
#FIXME: You can't actually use the credentials for anything elsewhere in Fog
|
||||||
#FIXME: Doesn't do any validation on the policy
|
#FIXME: Doesn't do any validation on the policy
|
||||||
def put_user_policy(user_name, policy_name, policy_document)
|
def put_user_policy(user_name, policy_name, policy_document)
|
||||||
if data[:users].keys.include? user_name
|
if data[:users].has_key? user_name
|
||||||
response = Excon::Response.new
|
|
||||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
|
||||||
response.status = 200
|
|
||||||
data[:users][user_name][:policies][policy_name] = policy_document
|
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
|
else
|
||||||
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
|
raise Fog::AWS::IAM::NotFound.new("The user with name #{user_name} cannot be found.")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue