diff options
Diffstat (limited to 'test/gitlabstub/cmd/server')
-rw-r--r-- | test/gitlabstub/cmd/server/main.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/gitlabstub/cmd/server/main.go b/test/gitlabstub/cmd/server/main.go index 3e33daaa..9820b722 100644 --- a/test/gitlabstub/cmd/server/main.go +++ b/test/gitlabstub/cmd/server/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "crypto/tls" "errors" "flag" "log" @@ -16,11 +17,25 @@ import ( var ( pagesRoot = flag.String("pages-root", "shared/pages", "The directory where pages are stored") + keyFile = flag.String("key-file", "", "Path to file certificate") + certFile = flag.String("cert-file", "", "Path to file certificate") ) func main() { flag.Parse() + var opts []gitlabstub.Option + + if *keyFile != "" && *certFile != "" { + log.Printf("Loading key pair: (%s) - (%s)", *certFile, *keyFile) + cert, err := tls.LoadX509KeyPair(*certFile, *keyFile) + if err != nil { + log.Fatalf("error loading certificate: %v", err) + } + + opts = append(opts, gitlabstub.WithCertificate(cert)) + } + if err := os.Chdir(*pagesRoot); err != nil { log.Fatalf("error chdir in %s: %v", *pagesRoot, err) } @@ -30,12 +45,18 @@ func main() { log.Fatalf("error getting current dir: %v", err) } - server, err := gitlabstub.NewUnstartedServer(gitlabstub.WithPagesRoot(wd)) + opts = append(opts, gitlabstub.WithPagesRoot(wd)) + + server, err := gitlabstub.NewUnstartedServer(opts...) if err != nil { log.Fatalf("error starting the server: %v", err) } - server.Start() + if server.TLS != nil { + server.StartTLS() + } else { + server.Start() + } log.Printf("listening on %s\n", server.URL) |