Class: IpcAuthpipe::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/ipcauthpipe/processor.rb

Overview

This is the main entry point that accepts incoming request strings, validates and splits them into command/parameters parts and delegates processing to the command’s handler

Instance Method Summary collapse

Instance Method Details

#call_handler_for(request) ⇒ Object

Delegates processing to a concrete handler of request’s command



31
32
33
34
# File 'lib/ipcauthpipe/processor.rb', line 31

def call_handler_for(request)
  Log.debug "Calling #{request[:command].capitalize} handler with [#{request[:params]}] as a parameter"
  IpcAuthpipe::Handler.const_get(request[:command].capitalize).process(request[:params])
end

#process(request) ⇒ Object

Accepts request as a single string, splits it into parts goes onto delegating. Returns handler’s response back to the caller



10
11
12
13
14
15
16
17
18
# File 'lib/ipcauthpipe/processor.rb', line 10

def process(request)
  Log.debug "Processing request: #{request.rstrip}"
  begin
    call_handler_for split_request(request)
  rescue Exception => excp
    Log.fatal "#{excp.class}, #{excp.message}"
    raise
  end
end

#split_request(req) ⇒ Object

Splits request into a command and it’s parameters, validating command on the way. Raises RuntimeError on invalid command or (that’s actually the same thing) unparsable request

Raises:

  • (RuntimeError)


22
23
24
25
26
27
28
# File 'lib/ipcauthpipe/processor.rb', line 22

def split_request(req)
  raise RuntimeError, 'Invalid request received' unless /^(PRE|AUTH|PASSWD|ENUMERATE)(?:$| (.*)$)/.match(req)
  {
    :command => $1,
    :params => $2.nil? || $2.empty? ? nil : $2
  }
end