Skip to content

Commit

Permalink
fix: Expand DevMode flag to set values for external access (#601)
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Goodell <[email protected]>
  • Loading branch information
Lenny Goodell authored Sep 13, 2023
1 parent 5491853 commit db3759c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"math"
"net"
"net/url"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -287,6 +288,12 @@ func (cp *Processor) Process(
host := "localhost"
config := serviceConfig.GetBootstrap()

if config.Service != nil {
// These are needed so the Service can receive HTTP calls from services running in Docker, like Core Command to Device Service
config.Service.Host = getLocalIP()
config.Service.ServerBindAddr = "0.0.0.0"
}

if config.MessageBus != nil {
config.MessageBus.Host = host
}
Expand Down Expand Up @@ -316,6 +323,22 @@ func (cp *Processor) Process(
return err
}

func getLocalIP() string {
// Because of how UDP works, the connection is not established - no handshake is performed, no data is sent.
// The purpose of this is to get the local IP address that a UDP connection would use if it were sending data to
// the external destination address.
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
// Since this is for Dev Mode, just default to localhost when can't get the actual IP
return "localhost"
}
defer conn.Close()

localAddress := conn.LocalAddr().(*net.UDPAddr)

return localAddress.IP.String()
}

func applyRemoteHosts(remoteHosts []string, serviceConfig interfaces.Configuration) error {
if len(remoteHosts) != 3 {
return invalidRemoteHostsError
Expand Down

0 comments on commit db3759c

Please sign in to comment.