Class: RobotArmy::Officer

Inherits:
Soldier show all
Defined in:
lib/robot-army/officer.rb

Instance Attribute Summary

Attributes inherited from Soldier

#messenger

Instance Method Summary collapse

Methods inherited from Soldier

#initialize, #listen

Constructor Details

This class inherits a constructor from RobotArmy::Soldier

Instance Method Details

#ask_for_password(user) ⇒ Object



31
32
33
34
# File 'lib/robot-army/officer.rb', line 31

def ask_for_password(user)
  messenger.post(:status => 'password', :data => {:as => user, :user => ENV['USER']})
  RobotArmy::Connection.handle_response messenger.get
end

#run(command, data) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/robot-army/officer.rb', line 2

def run(command, data)
  case command
  when :eval
    debug "officer delegating eval command for user=#{data[:user].inspect}"
    RobotArmy::Connection.localhost(data[:user], proc{ ask_for_password(data[:user]) }) do |local|
      local.post(:command => command, :data => data)
      
      loop do
        # we want to stay in this loop as long as we 
        # have proxy requests coming back from our child
        response = local.get
        case response[:status]
        when 'proxy'
          # forward proxy requests on to our parent
          messenger.post(response)
          # and send the response back to our child
          local.post(messenger.get)
        else
          return RobotArmy::Connection.handle_response(response)
        end
      end
    end
  when :exit
    super
  else
    super
  end
end