lib/routes/main.rb in gaptool-server-0.5.2 vs lib/routes/main.rb in gaptool-server-0.5.3

- old
+ new

@@ -76,15 +76,15 @@ put '/register' do 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 host_key = "instance:#{data['role']}:#{data['environment']}:#{data['secret']}" - host_data = redis.hgetall(host_key) + host_data = $redis.hgetall(host_key) unless host_data error 403 end - @instance = @ec2.instances[host_data['instance']] + @instance = @ec2.instances[host_data['instance_id']] hostname = @instance.dns_name $redis.del(host_key) @apps = [] $redis.keys("app:*").each do |app| if $redis.hget(app, 'role') == data['role'] @@ -95,11 +95,11 @@ data.merge!("hostname" => hostname) data.merge!("apps" => @apps.to_json) data.merge!("instance" => @instance.id) hash2redis("host:#{data['role']}:#{data['environment']}:#{@instance.id}", data) - @chef_repo = data['chef_repo'] || $redis.hget('config', 'chefrepo') - @chef_branch = data['chef_branch'] || $redis.hget('config', 'chefbranch') + @chef_repo = host_data['chef_repo'] && !host_data['chef_repo'].empty? ? host_data['chef_repo'] : $redis.hget('config', 'chefrepo') + @chef_branch = host_data['chef_branch'] && !host_data['chef_branch'].empty? ? host_data['chef_branch'] : $redis.hget('config', 'chefbranch') @initkey = $redis.hget('config', 'initkey') @json = { 'hostname' => hostname, 'recipe' => 'init', 'number' => @instance.id,