Skip to content

Commit 268fa36

Browse files
committed
Added STATS_USER_ENV and STATS_PASS_ENV [fixes #186]
1 parent 32ad351 commit 268fa36

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ENV CONNECTION_MODE="http-server-close" \
1818
MODE="default" \
1919
PROXY_INSTANCE_NAME="docker-flow" \
2020
SERVICE_NAME="proxy" \
21-
STATS_USER="admin" STATS_PASS="admin" \
21+
STATS_USER="admin" STATS_USER_ENV="STATS_USER" STATS_PASS="admin" STATS_PASS_ENV="STATS_PASS" \
2222
TIMEOUT_HTTP_REQUEST="5" TIMEOUT_HTTP_KEEP_ALIVE="15" TIMEOUT_CLIENT="20" TIMEOUT_CONNECT="5" TIMEOUT_QUEUE="30" TIMEOUT_SERVER="20" TIMEOUT_TUNNEL="3600" \
2323
USERS="" \
2424
EXTRA_FRONTEND="" \

docs/config.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ The following environment variables can be used to configure the *Docker Flow Pr
2727
|SERVICE_NAME |The name of the service. It must be the same as the value of the `--name` argument used to create the proxy service. Used only in the *swarm* mode.|No|proxy|my-proxy|
2828
|SKIP_ADDRESS_VALIDATION|Whether to skip validating service address before reconfiguring the proxy.|No|false|true|
2929
|STATS_USER |Username for the statistics page |No |admin |my-user|
30+
|STATS_USER_ENV |The name of the environment variable that holds the username for the statistics page|No|STATS_USER|MY_USER|
3031
|STATS_PASS |Password for the statistics page |No |admin |my-pass|
32+
|STATS_PASS_ENV |The name of the environment variable that holds the password for the statistics page|No|STATS_PASS|MY_PASS|
3133
|TIMEOUT_CLIENT |The client timeout in seconds |No |20 |5 |
3234
|TIMEOUT_CONNECT |The connect timeout in seconds |No |5 |3 |
3335
|TIMEOUT_QUEUE |The queue timeout in seconds |No |30 |10 |

proxy/ha_proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ func (m HaProxy) getConfigData() ConfigData {
198198
d.TimeoutTunnel = GetSecretOrEnvVar("TIMEOUT_TUNNEL", "3600")
199199
d.TimeoutHttpRequest = GetSecretOrEnvVar("TIMEOUT_HTTP_REQUEST", "5")
200200
d.TimeoutHttpKeepAlive = GetSecretOrEnvVar("TIMEOUT_HTTP_KEEP_ALIVE", "15")
201-
d.StatsUser = GetSecretOrEnvVar("STATS_USER", "admin")
202-
d.StatsPass = GetSecretOrEnvVar("STATS_PASS", "admin")
201+
d.StatsUser = GetSecretOrEnvVar(os.Getenv("STATS_USER_ENV"), "admin")
202+
d.StatsPass = GetSecretOrEnvVar(os.Getenv("STATS_PASS_ENV"), "admin")
203203
usersString := GetSecretOrEnvVar("USERS", "")
204204
encryptedString := GetSecretOrEnvVar("USERS_PASS_ENCRYPTED", "")
205205
if len(usersString) > 0 {

proxy/ha_proxy_test.go

+40-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ config2 fe content
8888
config1 be content
8989
9090
config2 be content`
91+
os.Setenv("STATS_USER_ENV", "STATS_USER")
92+
os.Setenv("STATS_PASS_ENV", "STATS_PASS")
9193
suite.Run(t, s)
9294
}
9395

@@ -1107,7 +1109,7 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesValuesWithEnvVa
11071109
{"STATS_PASS", "stats auth admin:admin", "stats auth admin:my-pass", "my-pass"},
11081110
}
11091111
for _, t := range tests {
1110-
timeoutOrig := os.Getenv(t.envKey)
1112+
envOrig := os.Getenv(t.envKey)
11111113
os.Setenv(t.envKey, t.value)
11121114
var actualData string
11131115
expectedData := fmt.Sprintf(
@@ -1124,7 +1126,43 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_ReplacesValuesWithEnvVa
11241126

11251127
s.Equal(expectedData, actualData)
11261128

1127-
os.Setenv(t.envKey, timeoutOrig)
1129+
os.Setenv(t.envKey, envOrig)
1130+
}
1131+
}
1132+
1133+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_UsersStatsUserEnvAndStatsPassEnv() {
1134+
tests := []struct {
1135+
envKey string
1136+
before string
1137+
after string
1138+
value string
1139+
envKeyName string
1140+
}{
1141+
{"MY_USER", "stats auth admin:admin", "stats auth my-user:admin", "my-user", "STATS_USER_ENV"},
1142+
{"MY_PASS", "stats auth admin:admin", "stats auth admin:my-pass", "my-pass", "STATS_PASS_ENV"},
1143+
}
1144+
for _, t := range tests {
1145+
os.Setenv(t.envKeyName, t.envKey)
1146+
envOrig := os.Getenv(t.envKey)
1147+
envKeyOrig := os.Getenv(t.envKeyName)
1148+
os.Setenv(t.envKey, t.value)
1149+
var actualData string
1150+
expectedData := fmt.Sprintf(
1151+
"%s%s",
1152+
strings.Replace(s.TemplateContent, t.before, t.after, -1),
1153+
s.ServicesContent,
1154+
)
1155+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
1156+
actualData = string(data)
1157+
return nil
1158+
}
1159+
1160+
NewHaProxy(s.TemplatesPath, s.ConfigsPath).CreateConfigFromTemplates()
1161+
1162+
s.Equal(expectedData, actualData)
1163+
1164+
os.Setenv(t.envKey, envOrig)
1165+
os.Setenv(t.envKeyName, envKeyOrig)
11281166
}
11291167
}
11301168

0 commit comments

Comments
 (0)