Skip to content

Commit

Permalink
[CNS] refactor: remove redundant check for TLSSettings.TLSPort (#2780)
Browse files Browse the repository at this point in the history
refactor: remove redundant check for TLSSettings.TLSPort
  • Loading branch information
jackieluc authored and paulyufan2 committed Jun 18, 2024
1 parent d0b4989 commit 3c88f7c
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cns/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,21 @@ func (service *Service) AddListener(config *common.ServiceConfig) error {

// only use TLS connection for DNC/CNS listener:
if config.TLSSettings.TLSPort != "" {
if config.TLSSettings.TLSPort != "" {
// listener.URL.Host will always be hostname:port, passed in to CNS via CNS command
// else it will default to localhost
// extract hostname and override tls port.
hostParts := strings.Split(nodeListener.URL.Host, ":")
tlsAddress := net.JoinHostPort(hostParts[0], config.TLSSettings.TLSPort)

// Start the listener and HTTP and HTTPS server.
tlsConfig, err := getTLSConfig(config.TLSSettings, config.ErrChan) //nolint
if err != nil {
log.Printf("Failed to compose Tls Configuration with error: %+v", err)
return errors.Wrap(err, "could not get tls config")
}
// listener.URL.Host will always be hostname:port, passed in to CNS via CNS command
// else it will default to localhost
// extract hostname and override tls port.
hostParts := strings.Split(nodeListener.URL.Host, ":")
tlsAddress := net.JoinHostPort(hostParts[0], config.TLSSettings.TLSPort)

// Start the listener and HTTP and HTTPS server.
tlsConfig, err := getTLSConfig(config.TLSSettings, config.ErrChan) //nolint
if err != nil {
log.Printf("Failed to compose Tls Configuration with error: %+v", err)
return errors.Wrap(err, "could not get tls config")
}

if err := nodeListener.StartTLS(config.ErrChan, tlsConfig, tlsAddress); err != nil {
return errors.Wrap(err, "could not start tls")
}
if err := nodeListener.StartTLS(config.ErrChan, tlsConfig, tlsAddress); err != nil {
return errors.Wrap(err, "could not start tls")
}
}

Expand Down

0 comments on commit 3c88f7c

Please sign in to comment.