Class: Sambot::DeveloperWorkflow::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/developer_workflow/proxy.rb

Constant Summary collapse

CONFIG_PATH =
'/tmp/haproxy.conf'

Class Method Summary collapse

Class Method Details

.start(forwards) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sambot/developer_workflow/proxy.rb', line 9

def self.start(forwards)
  template_path = FileManagement::TemplateProvider.get_path('haproxy.conf.erb')
  input = File.read(template_path)
  eruby = Erubis::Eruby.new(input)
  services = forwards.map do |key, value|
    {
      name: key.to_s.split('.')[0],
      ip: value[:ip],
      tunnel_port: value[:local_port],
      local_port: value[:port]
    }
  end
  services.each do |service|
    UI.debug("Proxying #{service[:name]}.brighter.io:#{service[:local_port]} to #{service[:ip]}:#{service[:tunnel_port]}")
  end
  contents = eruby.evaluate({services: services})
  File.write(CONFIG_PATH, contents)
  Runtime.sudo("haproxy -f #{CONFIG_PATH}")
end

.stopObject



29
30
31
# File 'lib/sambot/developer_workflow/proxy.rb', line 29

def self.stop
  Runtime.sudo("killall haproxy")
end