Skip to content

Commit b4c8a9c

Browse files
Merge pull request #69 from nicholasjackson/f-tls-configurable
Enable TLS for API can be disabled
2 parents faa9bc8 + 86ad7ef commit b4c8a9c

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

.github/workflows/go.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ jobs:
5858
matrix:
5959
tags:
6060
- "@k8s_canary_existing"
61-
#- "@k8s_canary_none"
62-
#- "@k8s_canary_rollback"
63-
#- "@k8s_canary_with_post_deployment_test"
64-
#- "@k8s_canary_with_post_deployment_test_fail"
65-
# - "@nomad_canary_existing"
61+
- "@k8s_canary_none"
62+
- "@k8s_canary_rollback"
63+
- "@k8s_canary_with_post_deployment_test"
64+
- "@k8s_canary_with_post_deployment_test_fail"
65+
#- "@nomad_canary_existing"
6666
steps:
6767
- uses: actions/checkout@v2
6868

pkg/api/server.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,32 @@ func New(config *ServerConfig, p interfaces.Provider, l hclog.Logger) (*Server,
8080

8181
// Start the server and block until complete
8282
func (a *Server) Start() error {
83-
// Create TLS listener.
84-
a.logger.Info("HTTPS Listening on ", "address", a.config.TLSBindAddress, "port", a.config.TLSBindPort)
85-
l, err := net.Listen("tcp4", fmt.Sprintf("%s:%d", a.config.TLSBindAddress, a.config.TLSBindPort))
86-
if err != nil {
87-
return fmt.Errorf("unable to create TCP listener: %s", err)
88-
}
89-
90-
a.httpsListener = l
83+
errChan := make(chan error)
9184

92-
a.httpsServer = &http.Server{
93-
Handler: a.router,
94-
ReadTimeout: 10 * time.Second,
95-
WriteTimeout: 10 * time.Second,
96-
}
85+
if a.config.TLSBindAddress != "" {
86+
// Create TLS listener.
87+
a.logger.Info("HTTPS Listening on ", "address", a.config.TLSBindAddress, "port", a.config.TLSBindPort)
88+
l, err := net.Listen("tcp4", fmt.Sprintf("%s:%d", a.config.TLSBindAddress, a.config.TLSBindPort))
89+
if err != nil {
90+
return fmt.Errorf("unable to create TCP listener: %s", err)
91+
}
9792

98-
errChan := make(chan error)
93+
a.httpsListener = l
9994

100-
// start the TLS endpoint
101-
go func() {
102-
err := a.httpsServer.Serve(tls.NewListener(l, a.tlsConfig))
103-
if err != nil && err != http.ErrServerClosed {
104-
errChan <- fmt.Errorf("unable to start TLS server: %s", err)
95+
a.httpsServer = &http.Server{
96+
Handler: a.router,
97+
ReadTimeout: 10 * time.Second,
98+
WriteTimeout: 10 * time.Second,
10599
}
106-
}()
100+
101+
// start the TLS endpoint
102+
go func() {
103+
err := a.httpsServer.Serve(tls.NewListener(l, a.tlsConfig))
104+
if err != nil && err != http.ErrServerClosed {
105+
errChan <- fmt.Errorf("unable to start TLS server: %s", err)
106+
}
107+
}()
108+
}
107109

108110
// if we are listening on plain HTTP start the server
109111
if a.config.HTTPBindAddress != "" {

0 commit comments

Comments
 (0)