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
|