Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Expand DevMode flag to set values for external access #601

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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