feature-#239: Econe server now responds to get. Authorization improvements

This commit is contained in:
Tino Vázquez committed 2010-05-10 17:13:43 +02:00
1 parent 0029dd404b
commit 73d8a739fa
2 files changed
+18 -6

No files matched your search

+7 -3
View File
@@ -69,6 +69,8 @@ class EC2QueryServer < CloudServer
@server_host=@config[:server]
end
@server_port=@config[:port]
print_configuration
end
@@ -79,7 +81,7 @@ class EC2QueryServer < CloudServer
# EC2 protocol authentication function
# params:: of the request
# [return] true if authenticated
def authenticate?(params)
def authenticate?(params,env)
user = get_user(params['AWSAccessKeyId'])
return false if !user
@@ -88,9 +90,9 @@ class EC2QueryServer < CloudServer
signature = AWS.encode(
user[:password],
AWS.canonical_string(signature_params, @server_host),
AWS.canonical_string(signature_params, @server_host + ":" + @server_port, env['REQUEST_METHOD']),
false)
return params['Signature']==signature
end
@@ -166,6 +168,7 @@ class EC2QueryServer < CloudServer
#Start the VM.
vm = VirtualMachine.new(VirtualMachine.build_xml, one_client)
puts template_text
rc = vm.allocate(template_text)
return rc, 401 if OpenNebula::is_error?(rc)
@@ -206,6 +209,7 @@ class EC2QueryServer < CloudServer
one_client = one_client_user(user)
vmid=params['InstanceId.1']
tmp, vmid=vmid.split('-') if vmid[0]==?i
erb_vm = VirtualMachine.new(VirtualMachine.build_xml(vmid),one_client)
rc = erb_vm.info
+11 -3
View File
@@ -59,12 +59,20 @@ set :port, $econe_server.config[:port]
##############################################################################
before do
if !$econe_server.authenticate?(params)
if !$econe_server.authenticate?(params,env)
halt 401, 'Invalid credentials'
end
end
post '/' do
do_http_request(params)
end
get '/' do
do_http_request(params)
end
def do_http_request(params)
case params['Action']
when 'UploadImage'
result,rc = $econe_server.upload_image(params)
@@ -79,10 +87,10 @@ post '/' do
when 'TerminateInstances'
result,rc = $econe_server.terminate_instances(params)
end
if OpenNebula::is_error?(result)
halt rc, result.message
end
result
result
end