lib/isomorfeus/puppetmaster/server/executor_middleware.rb in isomorfeus-puppetmaster-0.6.15 vs lib/isomorfeus/puppetmaster/server/executor_middleware.rb in isomorfeus-puppetmaster-0.6.16
- old
+ new
@@ -16,21 +16,21 @@
request = Rack::Request.new(env)
response = nil
unless request.body.nil?
request_hash = Oj.load(request.body.read, mode: :strict)
if request_hash['key'] != @@request_key
- STDERR.puts "wrong key"
response = Rack::Response.new(Oj.dump({ 'error' => 'wrong key given, execution denied' }),
401,
'Content-Type' => 'application/json')
else
begin
if Isomorfeus.respond_to?(:init_store)
Isomorfeus.init_store
Isomorfeus.store.clear! if Isomorfeus.store.respond_to?(:clear!)
end
result = TOPLEVEL_BINDING.eval(request_hash['code']) if request_hash['code']
- response = Rack::Response.new(Oj.dump({ 'result' => result }),
+ result = result.value if result.is_a?(Promise)
+ response = Rack::Response.new(Oj.dump({ 'result' => result }, circular: true),
200,
'Content-Type' => 'application/json')
rescue Exception => e
response = Rack::Response.new(Oj.dump({ 'error' => "#{e.class}: #{e.message}", 'backtrace' => e.backtrace&.join("\n") }),
200,