Skip to content

Commit 23ca5d0

Browse files
committed
Added tls-config folder
1 parent 95b42bd commit 23ca5d0

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ RUN apk --no-cache add --virtual build-dependencies \
1414
&& apk del --purge build-dependencies
1515

1616
RUN mkdir /config
17+
RUN mkdir /tls
1718

1819
VOLUME /config
1920

20-
ADD server.crt /
21-
ADD server.key /
21+
ADD server.crt /tls
22+
ADD server.key /tls
2223

2324
EXPOSE 8082 8083 8084
2425

25-
ENTRYPOINT ["mmock","-config-path","/config"]
26+
ENTRYPOINT ["mmock","-config-path","/config","-tls-path","/tls"]

mmock.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ func getVarsProcessor() vars.Processor {
114114
return vars.Processor{FillerFactory: vars.MockFillerFactory{FakeAdapter: fakedata.FakeAdapter{}}}
115115
}
116116

117-
func startServer(ip string, port, portTLS int, done chan bool, router server.Resolver, mLog chan definition.Match, scenario scenario.Director, varsProcessor vars.Processor, spier match.Spier) {
117+
func startServer(ip string, port, portTLS int, configTLS string, done chan bool, router server.Resolver, mLog chan definition.Match, scenario scenario.Director, varsProcessor vars.Processor, spier match.Spier) {
118118
dispatcher := server.Dispatcher{
119119
IP: ip,
120120
Port: port,
121121
PortTLS: portTLS,
122+
ConfigTLS: configTLS,
122123
Resolver: router,
123124
Translator: translate.HTTP{},
124125
Processor: varsProcessor,
@@ -145,6 +146,7 @@ func main() {
145146
banner()
146147
outIP := getOutboundIP()
147148
path, err := filepath.Abs("./config")
149+
TLS, err := filepath.Abs("./tls")
148150
if err != nil {
149151
panic(ErrNotFoundDefaultPath)
150152
}
@@ -157,6 +159,7 @@ func main() {
157159
cPort := flag.Int("console-port", 8082, "Console server Port")
158160
console := flag.Bool("console", true, "Console enabled (true/false)")
159161
cPath := flag.String("config-path", path, "Mocks definition folder")
162+
cTLS := flag.String("tls-path", TLS, "TLS config folder (server.crt and server.key should be inside)")
160163

161164
flag.Parse()
162165

@@ -180,7 +183,7 @@ func main() {
180183
}
181184
defer statistics.Stop()
182185

183-
go startServer(*sIP, *sPort, *sPortTLS, done, router, mLog, scenario, varsProcessor, spy)
186+
go startServer(*sIP, *sPort, *sPortTLS, *cTLS, done, router, mLog, scenario, varsProcessor, spy)
184187
log.Printf("HTTP Server running at %s:%d\n", *sIP, *sPort)
185188
log.Printf("HTTPS Server running at %s:%d\n", *sIP, *sPortTLS)
186189
if *console {

server/dispatcher.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"math/rand"
77
"net/http"
8+
"path"
89
"strconv"
910
"time"
1011

@@ -22,6 +23,7 @@ type Dispatcher struct {
2223
IP string
2324
Port int
2425
PortTLS int
26+
ConfigTLS string
2527
Resolver Resolver
2628
Translator translate.MessageTranslator
2729
Processor vars.Processor
@@ -113,6 +115,8 @@ func (di *Dispatcher) getMatchingResult(request *definition.Request) (*definitio
113115
func (di Dispatcher) Start() {
114116
addr := fmt.Sprintf("%s:%d", di.IP, di.Port)
115117
addrTLS := fmt.Sprintf("%s:%d", di.IP, di.PortTLS)
118+
crt := path.Join(di.ConfigTLS, "server.crt")
119+
key := path.Join(di.ConfigTLS, "server.key")
116120

117121
errCh := make(chan error)
118122

@@ -121,7 +125,7 @@ func (di Dispatcher) Start() {
121125
}()
122126

123127
go func() {
124-
errCh <- http.ListenAndServeTLS(addrTLS, "server.crt", "server.key", &di)
128+
errCh <- http.ListenAndServeTLS(addrTLS, crt, key, &di)
125129
}()
126130

127131
err := <-errCh
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)