event_shipper / lib / event_shipper / proxy.rb

require 'redis'
require 'yaml'
require 'clamp'

require_relative 'filters'
require_relative 'udp'

module EventShipper
  class Proxy < Clamp::Command

    option %w(-c --config), "FILE", "Location of the configuration file."

    def execute
      fail "Please specify a configuration file to use on the command line. (--config)" \
        unless config

      configure_with YAML.load_file(config)

        trap('SIGINFO') { puts transport.stats }
      rescue ArgumentError
        # unsupported signal SIGINFO

      transport.dispatch { |queue, message| 
        # puts message }
        redis.lpush queue, message }

    attr_reader :host, :port
    attr_reader :listen
    attr_reader :userdb
    attr_reader :redis
    attr_reader :transport

    def configure_with configuration
      @listen = configuration['listen']
      @host, @port = listen['host'], listen['port']
      @transport = UDP.new(host, port)

      if configuration['encrypt']
        users = configuration['users']
        @userdb = Hash[users.map { |str| str.partition('/').values_at(0,2) }]

        transport.wrap Filter::Decrypt.new(userdb)

      redis_config = configuration['redis']
      @redis = Redis.new(
        host: redis_config['host'], 
        port: redis_config['port'])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.