Skip to content

Commit ef8df13

Browse files
committed
Refactoring [ci skip]
1 parent b6c635b commit ef8df13

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

logging/logging.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (h *handler) mainLoop() {
2424
}
2525
}
2626

27-
// Starts listening to rsyslog and outputting it to stdout
27+
// StartLogging listens to rsyslog and outputs entries to stdout
2828
var StartLogging = func() {
2929
s := syslog.NewServer()
3030
s.AddHandler(newHandler())

proxy/ha_proxy.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,8 @@ backend dummy-be
200200
}
201201

202202
func (m HaProxy) getConfigData() ConfigData {
203-
certPaths := m.GetCertPaths()
204-
certsString := []string{}
205-
if len(certPaths) > 0 {
206-
certsString = append(certsString, " ssl")
207-
for _, certPath := range certPaths {
208-
certsString = append(certsString, fmt.Sprintf("crt %s", certPath))
209-
}
210-
}
211-
if len(os.Getenv("CA_FILE")) > 0 {
212-
if len(certsString) == 0 {
213-
certsString = append(certsString, " ssl")
214-
}
215-
cf := "ca-file " + os.Getenv("CA_FILE") + " verify optional"
216-
certsString = append(certsString, cf)
217-
}
218203
d := ConfigData{
219-
CertsString: strings.Join(certsString, " "),
204+
CertsString: strings.Join(m.getCerts(), " "),
220205
}
221206
d.ConnectionMode = GetSecretOrEnvVar("CONNECTION_MODE", "http-server-close")
222207
d.SslBindCiphers = GetSecretOrEnvVar("SSL_BIND_CIPHERS", "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS")
@@ -274,6 +259,25 @@ func (m HaProxy) getConfigData() ConfigData {
274259
return d
275260
}
276261

262+
func (m *HaProxy) getCerts() []string {
263+
certPaths := m.GetCertPaths()
264+
certs := []string{}
265+
if len(certPaths) > 0 {
266+
certs = append(certs, " ssl")
267+
for _, certPath := range certPaths {
268+
certs = append(certs, fmt.Sprintf("crt %s", certPath))
269+
}
270+
}
271+
if len(os.Getenv("CA_FILE")) > 0 {
272+
if len(certs) == 0 {
273+
certs = append(certs, " ssl")
274+
}
275+
cf := "ca-file " + os.Getenv("CA_FILE") + " verify optional"
276+
certs = append(certs, cf)
277+
}
278+
return certs
279+
}
280+
277281
func (m *HaProxy) addCompression(data *ConfigData) {
278282
if len(os.Getenv("COMPRESSION_ALGO")) > 0 {
279283
data.ExtraDefaults += fmt.Sprintf(`

proxy/ha_proxy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCaFile_WhenEnvVarIs
14591459
var actualData string
14601460
tmpl := strings.Replace(
14611461
s.TemplateContent, "bind *:443",
1462-
"bind *:443 ssl ca-file " + caFile + " verify optional",
1462+
"bind *:443 ssl ca-file "+caFile+" verify optional",
14631463
-1)
14641464
expectedData := tmpl + s.ServicesContent
14651465
writeFile = func(filename string, data []byte, perm os.FileMode) error {

run.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ type runner interface {
66
Execute(args []string) error
77
}
88

9-
type Run struct{}
9+
type run struct{}
1010

11-
var NewRun = func() runner {
12-
return &Run{}
11+
var newRun = func() runner {
12+
return &run{}
1313
}
1414

15-
func (m *Run) Execute(args []string) error {
15+
// Execute runs the proxy
16+
func (m *run) Execute(args []string) error {
1617
return haproxy.HaProxy{}.RunCmd([]string{})
1718
}

run_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (s *RunTestSuite) SetupTest() {
1818
// NewRun
1919

2020
func (s RunTestSuite) Test_NewRun_ReturnsNewStruct() {
21-
s.NotNil(NewRun())
21+
s.NotNil(newRun())
2222
}
2323

2424
// Suite

server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (m *Serve) Execute(args []string) error {
4343
}
4444
logPrintf("Starting HAProxy")
4545
m.setConsulAddresses()
46-
NewRun().Execute([]string{})
46+
newRun().Execute([]string{})
4747
address := fmt.Sprintf("%s:%s", m.IP, m.Port)
4848
cert.Init()
4949
var server2 = server.NewServer(

server_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ func (s *ServerTestSuite) Test_Execute_ReturnsError_WhenHTTPListenAndServeFails(
126126
}
127127

128128
func (s *ServerTestSuite) Test_Execute_InvokesRunExecute() {
129-
orig := NewRun
129+
orig := newRun
130130
defer func() {
131-
NewRun = orig
131+
newRun = orig
132132
}()
133133
mockObj := getRunMock("")
134-
NewRun = func() runner {
134+
newRun = func() runner {
135135
return mockObj
136136
}
137137

0 commit comments

Comments
 (0)