Skip to content

Commit

Permalink
Fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Dec 4, 2016
1 parent 80c2fd8 commit 3ee0ae8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ENV TIMEOUT_SERVER "20"
ENV TIMEOUT_QUEUE "30"
ENV TIMEOUT_HTTP_REQUEST "5"
ENV TIMEOUT_HTTP_KEEP_ALIVE "15"
ENV STATS_USER "admin"
ENV STATS_PASS "admin"

EXPOSE 80
EXPOSE 443
Expand Down
2 changes: 1 addition & 1 deletion haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defaults
stats enable
stats refresh 30s
stats realm Strictly\ Private
stats auth admin:admin
stats auth {{.StatsUser}}:{{.StatsPass}}
stats uri /admin?stats

frontend services
Expand Down
18 changes: 9 additions & 9 deletions integration_tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ func (s IntegrationTestSuite) Test_Certs() {

s.Equal(200, resp.StatusCode)

// // HTTPS works
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
// req, _ = http.NewRequest("GET", url, nil)
// client = &http.Client{}
//
// resp, err := client.Do(req)
//
// s.NoError(err)
// s.Equal(200, resp.StatusCode)
// // HTTPS works
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
// req, _ = http.NewRequest("GET", url, nil)
// client = &http.Client{}
//
// resp, err := client.Do(req)
//
// s.NoError(err)
// s.Equal(200, resp.StatusCode)

// Can retrieve certs
url = fmt.Sprintf("http://%s:8080/v1/docker-flow-proxy/certs", os.Getenv("DOCKER_IP"))
Expand Down
34 changes: 22 additions & 12 deletions proxy/ha_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ type HaProxy struct {
var Instance Proxy

type ConfigData struct {
CertsString string
TimeoutConnect string
TimeoutClient string
TimeoutServer string
TimeoutQueue string
TimeoutHttpRequest string
CertsString string
TimeoutConnect string
TimeoutClient string
TimeoutServer string
TimeoutQueue string
TimeoutHttpRequest string
TimeoutHttpKeepAlive string
StatsUser string
StatsPass string
}

func NewHaProxy(templatesPath, configsPath string, certs map[string]bool) Proxy {
Expand Down Expand Up @@ -147,13 +149,15 @@ func (m HaProxy) getConfigData() ConfigData {
}
}
d := ConfigData{
CertsString: strings.Join(certs, " "),
TimeoutConnect: "5",
TimeoutClient: "20",
TimeoutServer: "20",
TimeoutQueue: "30",
TimeoutHttpRequest: "5",
CertsString: strings.Join(certs, " "),
TimeoutConnect: "5",
TimeoutClient: "20",
TimeoutServer: "20",
TimeoutQueue: "30",
TimeoutHttpRequest: "5",
TimeoutHttpKeepAlive: "15",
StatsUser: "admin",
StatsPass: "admin",
}
if len(os.Getenv("TIMEOUT_CONNECT")) > 0 {
d.TimeoutConnect = os.Getenv("TIMEOUT_CONNECT")
Expand All @@ -173,5 +177,11 @@ func (m HaProxy) getConfigData() ConfigData {
if len(os.Getenv("TIMEOUT_HTTP_KEEP_ALIVE")) > 0 {
d.TimeoutHttpKeepAlive = os.Getenv("TIMEOUT_HTTP_KEEP_ALIVE")
}
if len(os.Getenv("STATS_USER")) > 0 {
d.StatsUser = os.Getenv("STATS_USER")
}
if len(os.Getenv("STATS_PASS")) > 0 {
d.StatsPass = os.Getenv("STATS_PASS")
}
return d
}
31 changes: 16 additions & 15 deletions proxy/ha_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
"github.com/stretchr/testify/suite"
"os"
"os/exec"
"testing"
"strings"
"testing"
)

// Setup

type HaProxyTestSuite struct {
suite.Suite
TemplatesPath string
ConfigsPath string
Pid string
TemplatesPath string
ConfigsPath string
Pid string
TemplateContent string
ServicesContent string
}
Expand Down Expand Up @@ -147,24 +147,26 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCert() {
s.Equal(expectedData, actualData)
}

func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesTimeoutsWithEnvVars() {
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesValuesWithEnvVars() {
tests := []struct {
envKey string
before string
after string
after string
value string
}{
{ "TIMEOUT_CONNECT", "timeout connect 5s", "timeout connect 999s" },
{ "TIMEOUT_CLIENT", "timeout client 20s", "timeout client 999s" },
{ "TIMEOUT_SERVER", "timeout server 20s", "timeout server 999s" },
{ "TIMEOUT_QUEUE", "timeout queue 30s", "timeout queue 999s" },
{ "TIMEOUT_HTTP_REQUEST", "timeout http-request 5s", "timeout http-request 999s" },
{ "TIMEOUT_HTTP_KEEP_ALIVE", "timeout http-keep-alive 15s", "timeout http-keep-alive 999s" },
{"TIMEOUT_CONNECT", "timeout connect 5s", "timeout connect 999s", "999"},
{"TIMEOUT_CLIENT", "timeout client 20s", "timeout client 999s", "999"},
{"TIMEOUT_SERVER", "timeout server 20s", "timeout server 999s", "999"},
{"TIMEOUT_QUEUE", "timeout queue 30s", "timeout queue 999s", "999"},
{"TIMEOUT_HTTP_REQUEST", "timeout http-request 5s", "timeout http-request 999s", "999"},
{"TIMEOUT_HTTP_KEEP_ALIVE", "timeout http-keep-alive 15s", "timeout http-keep-alive 999s", "999"},
{"STATS_USER", "stats auth admin:admin", "stats auth my-user:admin", "my-user"},
{"STATS_PASS", "stats auth admin:admin", "stats auth admin:my-pass", "my-pass"},
}
for _, t := range tests {
timeoutOrig := os.Getenv(t.envKey)
os.Setenv(t.envKey, "999")
os.Setenv(t.envKey, t.value)
var actualFilename string
expectedFilename := fmt.Sprintf("%s/haproxy.cfg", s.ConfigsPath)
var actualData string
expectedData := fmt.Sprintf(
"%s%s",
Expand All @@ -179,7 +181,6 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesTimeoutsWithEnv

NewHaProxy(s.TemplatesPath, s.ConfigsPath, map[string]bool{}).CreateConfigFromTemplates()

s.Equal(expectedFilename, actualFilename)
s.Equal(expectedData, actualData)

os.Setenv(t.envKey, timeoutOrig)
Expand Down
2 changes: 1 addition & 1 deletion proxy/test_configs/tmpl/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defaults
stats enable
stats refresh 30s
stats realm Strictly\ Private
stats auth admin:admin
stats auth {{.StatsUser}}:{{.StatsPass}}
stats uri /admin?stats

frontend services
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (s *ServerTestSuite) Test_ServeHTTP_InvokesReconfigureExecute() {
s.ServiceReconfigure.AclName = "my-acl"
url := fmt.Sprintf("%s&aclName=my-acl", s.ReconfigureUrl)
req, _ := http.NewRequest("GET", url, nil)
// s.RequestReconfigure.u
// s.RequestReconfigure.u
s.invokesReconfigure(req, true)
}

Expand Down

0 comments on commit 3ee0ae8

Please sign in to comment.