Skip to content

Commit

Permalink
configure http-in if health uri or certs (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakolehm authored Dec 13, 2017
1 parent 006b58a commit 2ab5102
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/kontena/templates/haproxy/main.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defaults
<% end %>
<% end %>

<% if services.size > 0 %>
<% if services.size > 0 || ssl? || health_uri? %>
<%= http_in %>
<% end %>

Expand Down
12 changes: 12 additions & 0 deletions lib/kontena/views/common.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Kontena::Views
module Common

def ssl?
ENV['SSL_CERTS'] || ENV.any? { |env, value| env.start_with? 'SSL_CERT_' }
end

def health_uri?
ENV['KONTENA_LB_HEALTH_URI']
end
end
end
2 changes: 2 additions & 0 deletions lib/kontena/views/haproxy.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'erb'
require_relative 'common'
require_relative 'http_in'
require_relative 'http_backends'
require_relative 'tcp_proxies'

module Kontena::Views
class Haproxy
include Hanami::View
include Kontena::Views::Common

format :text
template 'haproxy/main'
Expand Down
7 changes: 3 additions & 4 deletions lib/kontena/views/http_in.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
require_relative 'common'

module Kontena::Views
class HttpIn
include Hanami::View
include Kontena::Views::Common

format :text
template 'haproxy/http_in'

def ssl?
ENV['SSL_CERTS'] || ENV.any? { |env, value| env.start_with? 'SSL_CERT_' }
end
end
end
36 changes: 34 additions & 2 deletions spec/kontena/views/haproxy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
describe Kontena::Views::Haproxy do

describe '.render' do
context 'stats' do
describe '.render' do
context 'http-in' do
it 'does not configure http-in by default' do
output = described_class.render(
format: :text,
services: [],
tcp_services: []
)
expect(output.match(/listen http-in/)).to be_falsey
end

it 'configures http-in if health uri is defined' do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with('KONTENA_LB_HEALTH_URI').and_return('/__health')
output = described_class.render(
format: :text,
services: [],
tcp_services: []
)
expect(output.match(/listen http-in/)).to be_truthy
end

it 'configures http-in if ssl certs' do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with('SSL_CERTS').and_return('cert...')
output = described_class.render(
format: :text,
services: [],
tcp_services: []
)
expect(output.match(/listen http-in/)).to be_truthy
end
end
context 'stats' do
it 'configures stats auth' do
allow(ENV).to receive(:[])
allow(ENV).to receive(:[]).with('STATS_PASSWORD').and_return('secrettzzz')
Expand Down

0 comments on commit 2ab5102

Please sign in to comment.