lib/routes/main.rb in gaptool-server-0.4.6 vs lib/routes/main.rb in gaptool-server-0.4.7
- old
+ new
@@ -1,8 +1,12 @@
# encoding: utf-8
class GaptoolServer < Sinatra::Application
+ error do
+ {error: "Sorry there was a nasty error - #{env['sinatra.error']}" }.to_json
+ end
+
get '/' do
"You must be lost. Read the instructions."
end
post '/redishash' do
@@ -88,12 +92,12 @@
data = JSON.parse request.body.read
AWS.config(:access_key_id => $redis.hget('config', 'aws_id'), :secret_access_key => $redis.hget('config', 'aws_secret'), :ec2_endpoint => "ec2.#{data['zone'].chop}.amazonaws.com")
@ec2 = AWS::EC2.new
@instance = @ec2.instances[$redis.get("instance:#{data['role']}:#{data['environment']}:#{data['secret']}")]
hostname = @instance.dns_name
- delete = $redis.del("instance:#{data['role']}:#{data['environment']}:#{data['secret']}")
- @apps = Array.new
+ $redis.del("instance:#{data['role']}:#{data['environment']}:#{data['secret']}")
+ @apps = []
$redis.keys("app:*").each do |app|
if $redis.hget(app, 'role') == data['role']
@apps << app.gsub('app:', '')
end
end
@@ -117,39 +121,38 @@
}.to_json
erb :init
end
get '/hosts' do
- out = Array.new
+ out = []
$redis.keys("host:*").each do |host|
out << $redis.hgetall(host)
end
out.to_json
end
get '/apps' do
- out = Hash.new
+ out = {}
$redis.keys("app:*").each do |app|
out.merge!(app => $redis.hgetall(app))
end
out.to_json
end
get '/hosts/:role' do
- out = Array.new
+ out = []
$redis.keys("host:#{params[:role]}:*").each do |host|
out << $redis.hgetall(host)
end
out.to_json
end
get '/instance/:id' do
- out = Array.new
$redis.hgetall($redis.keys("host:*:*:#{params[:id]}").first).to_json
end
get '/hosts/:role/:environment' do
- out = Array.new
+ out = []
unless params[:role] == "ALL"
$redis.keys("host:#{params[:role]}:#{params[:environment]}*").each do |host|
out << $redis.hgetall(host)
end
else