Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions api/types/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ type Endpoint struct {
Active bool `json:"active"`
}

func (e Endpoint) GetAPIHostname() string {
if e.APIHostname != "" {
return e.APIHostname
}
// Return legacy field for endpoints created before APIHostname was existing
return e.Hostname
}

func (e Endpoint) String() string {
return fmt.Sprintf("Endpoint[%s|%s|Network(%s)|Active(%v)]", e.ID, e.TargetNetnsPath, e.NetworkID, e.Active)
}
Expand Down
10 changes: 6 additions & 4 deletions web/networks_controller_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ func (c NetworksController) Connect(w http.ResponseWriter, r *http.Request, urlp

if len(activeEndpoints) == 0 {
w.WriteHeader(400)
json.NewEncoder(w).Encode(map[string]string{"error": "no active endpoint in network " + network.ID})
jsonerr := json.NewEncoder(w).Encode(map[string]string{"error": "no active endpoint in network " + network.ID})
if jsonerr != nil {
log.WithError(jsonerr).Error("Fail to encode error response")
}
return nil
}

log.Infof("Hijacking http connection and forward to %v", localEndpoint.Hostname)
h, ok := w.(http.Hijacker)
if !ok {
return errors.New("invalid response writer")
Expand Down Expand Up @@ -116,11 +118,11 @@ func (c NetworksController) Connect(w http.ResponseWriter, r *http.Request, urlp
}
options = append(options, sand.WithTlsConfig(config))
}
url := fmt.Sprintf("%s://%s:%d", scheme, endpoint.APIHostname, c.Config.HTTPPort)
url := fmt.Sprintf("%s://%s:%d", scheme, endpoint.GetAPIHostname(), c.Config.HTTPPort)
options = append(options, sand.WithURL(url))
client := sand.NewClient(options...)

log.Infof("forwarding connection to %v", url)
log.Infof("Forwarding connection to %v", url)
dstConn, err := client.NetworkConnect(ctx, network.ID, params.NetworkConnect{IP: ip, Port: port})
if err != nil {
socket.Close()
Expand Down