Skip to content

Commit 3ee0ae8

Browse files
committed
Fixes #31
1 parent 80c2fd8 commit 3ee0ae8

File tree

7 files changed

+52
-39
lines changed

7 files changed

+52
-39
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ENV TIMEOUT_SERVER "20"
2424
ENV TIMEOUT_QUEUE "30"
2525
ENV TIMEOUT_HTTP_REQUEST "5"
2626
ENV TIMEOUT_HTTP_KEEP_ALIVE "15"
27+
ENV STATS_USER "admin"
28+
ENV STATS_PASS "admin"
2729

2830
EXPOSE 80
2931
EXPOSE 443

haproxy.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defaults
2323
stats enable
2424
stats refresh 30s
2525
stats realm Strictly\ Private
26-
stats auth admin:admin
26+
stats auth {{.StatsUser}}:{{.StatsPass}}
2727
stats uri /admin?stats
2828

2929
frontend services

integration_tests/integration_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ func (s IntegrationTestSuite) Test_Certs() {
188188

189189
s.Equal(200, resp.StatusCode)
190190

191-
// // HTTPS works
192-
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
193-
// req, _ = http.NewRequest("GET", url, nil)
194-
// client = &http.Client{}
195-
//
196-
// resp, err := client.Do(req)
197-
//
198-
// s.NoError(err)
199-
// s.Equal(200, resp.StatusCode)
191+
// // HTTPS works
192+
// url = fmt.Sprintf("https://%s:8080/v2/test", os.Getenv("DOCKER_IP"))
193+
// req, _ = http.NewRequest("GET", url, nil)
194+
// client = &http.Client{}
195+
//
196+
// resp, err := client.Do(req)
197+
//
198+
// s.NoError(err)
199+
// s.Equal(200, resp.StatusCode)
200200

201201
// Can retrieve certs
202202
url = fmt.Sprintf("http://%s:8080/v1/docker-flow-proxy/certs", os.Getenv("DOCKER_IP"))

proxy/ha_proxy.go

+22-12
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ type HaProxy struct {
1818
var Instance Proxy
1919

2020
type ConfigData struct {
21-
CertsString string
22-
TimeoutConnect string
23-
TimeoutClient string
24-
TimeoutServer string
25-
TimeoutQueue string
26-
TimeoutHttpRequest string
21+
CertsString string
22+
TimeoutConnect string
23+
TimeoutClient string
24+
TimeoutServer string
25+
TimeoutQueue string
26+
TimeoutHttpRequest string
2727
TimeoutHttpKeepAlive string
28+
StatsUser string
29+
StatsPass string
2830
}
2931

3032
func NewHaProxy(templatesPath, configsPath string, certs map[string]bool) Proxy {
@@ -147,13 +149,15 @@ func (m HaProxy) getConfigData() ConfigData {
147149
}
148150
}
149151
d := ConfigData{
150-
CertsString: strings.Join(certs, " "),
151-
TimeoutConnect: "5",
152-
TimeoutClient: "20",
153-
TimeoutServer: "20",
154-
TimeoutQueue: "30",
155-
TimeoutHttpRequest: "5",
152+
CertsString: strings.Join(certs, " "),
153+
TimeoutConnect: "5",
154+
TimeoutClient: "20",
155+
TimeoutServer: "20",
156+
TimeoutQueue: "30",
157+
TimeoutHttpRequest: "5",
156158
TimeoutHttpKeepAlive: "15",
159+
StatsUser: "admin",
160+
StatsPass: "admin",
157161
}
158162
if len(os.Getenv("TIMEOUT_CONNECT")) > 0 {
159163
d.TimeoutConnect = os.Getenv("TIMEOUT_CONNECT")
@@ -173,5 +177,11 @@ func (m HaProxy) getConfigData() ConfigData {
173177
if len(os.Getenv("TIMEOUT_HTTP_KEEP_ALIVE")) > 0 {
174178
d.TimeoutHttpKeepAlive = os.Getenv("TIMEOUT_HTTP_KEEP_ALIVE")
175179
}
180+
if len(os.Getenv("STATS_USER")) > 0 {
181+
d.StatsUser = os.Getenv("STATS_USER")
182+
}
183+
if len(os.Getenv("STATS_PASS")) > 0 {
184+
d.StatsPass = os.Getenv("STATS_PASS")
185+
}
176186
return d
177187
}

proxy/ha_proxy_test.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
"github.com/stretchr/testify/suite"
88
"os"
99
"os/exec"
10-
"testing"
1110
"strings"
11+
"testing"
1212
)
1313

1414
// Setup
1515

1616
type HaProxyTestSuite struct {
1717
suite.Suite
18-
TemplatesPath string
19-
ConfigsPath string
20-
Pid string
18+
TemplatesPath string
19+
ConfigsPath string
20+
Pid string
2121
TemplateContent string
2222
ServicesContent string
2323
}
@@ -147,24 +147,26 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCert() {
147147
s.Equal(expectedData, actualData)
148148
}
149149

150-
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesTimeoutsWithEnvVars() {
150+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesValuesWithEnvVars() {
151151
tests := []struct {
152152
envKey string
153153
before string
154-
after string
154+
after string
155+
value string
155156
}{
156-
{ "TIMEOUT_CONNECT", "timeout connect 5s", "timeout connect 999s" },
157-
{ "TIMEOUT_CLIENT", "timeout client 20s", "timeout client 999s" },
158-
{ "TIMEOUT_SERVER", "timeout server 20s", "timeout server 999s" },
159-
{ "TIMEOUT_QUEUE", "timeout queue 30s", "timeout queue 999s" },
160-
{ "TIMEOUT_HTTP_REQUEST", "timeout http-request 5s", "timeout http-request 999s" },
161-
{ "TIMEOUT_HTTP_KEEP_ALIVE", "timeout http-keep-alive 15s", "timeout http-keep-alive 999s" },
157+
{"TIMEOUT_CONNECT", "timeout connect 5s", "timeout connect 999s", "999"},
158+
{"TIMEOUT_CLIENT", "timeout client 20s", "timeout client 999s", "999"},
159+
{"TIMEOUT_SERVER", "timeout server 20s", "timeout server 999s", "999"},
160+
{"TIMEOUT_QUEUE", "timeout queue 30s", "timeout queue 999s", "999"},
161+
{"TIMEOUT_HTTP_REQUEST", "timeout http-request 5s", "timeout http-request 999s", "999"},
162+
{"TIMEOUT_HTTP_KEEP_ALIVE", "timeout http-keep-alive 15s", "timeout http-keep-alive 999s", "999"},
163+
{"STATS_USER", "stats auth admin:admin", "stats auth my-user:admin", "my-user"},
164+
{"STATS_PASS", "stats auth admin:admin", "stats auth admin:my-pass", "my-pass"},
162165
}
163166
for _, t := range tests {
164167
timeoutOrig := os.Getenv(t.envKey)
165-
os.Setenv(t.envKey, "999")
168+
os.Setenv(t.envKey, t.value)
166169
var actualFilename string
167-
expectedFilename := fmt.Sprintf("%s/haproxy.cfg", s.ConfigsPath)
168170
var actualData string
169171
expectedData := fmt.Sprintf(
170172
"%s%s",
@@ -179,7 +181,6 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesTimeoutsWithEnv
179181

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

182-
s.Equal(expectedFilename, actualFilename)
183184
s.Equal(expectedData, actualData)
184185

185186
os.Setenv(t.envKey, timeoutOrig)

proxy/test_configs/tmpl/haproxy.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defaults
2323
stats enable
2424
stats refresh 30s
2525
stats realm Strictly\ Private
26-
stats auth admin:admin
26+
stats auth {{.StatsUser}}:{{.StatsPass}}
2727
stats uri /admin?stats
2828

2929
frontend services

server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ func (s *ServerTestSuite) Test_ServeHTTP_InvokesReconfigureExecute() {
516516
s.ServiceReconfigure.AclName = "my-acl"
517517
url := fmt.Sprintf("%s&aclName=my-acl", s.ReconfigureUrl)
518518
req, _ := http.NewRequest("GET", url, nil)
519-
// s.RequestReconfigure.u
519+
// s.RequestReconfigure.u
520520
s.invokesReconfigure(req, true)
521521
}
522522

0 commit comments

Comments
 (0)