TUN-3461: Show all origin services in the UI

This commit is contained in:
Adam Chalmers 2020-11-09 19:22:03 -06:00
parent 8c6181db9f
commit 4698ec8dee
4 changed files with 23 additions and 17 deletions

View File

@ -246,7 +246,7 @@ type OriginRequestConfig struct {
ProxyAddress *string `yaml:"proxyAddress"`
// Listen port for the proxy.
ProxyPort *uint `yaml:"proxyPort"`
// Valid options are 'socks', 'ssh' or empty.
// Valid options are 'socks' or empty.
ProxyType *string `yaml:"proxyType"`
}

View File

@ -395,7 +395,7 @@ func StartServer(
hostname,
metricsListener.Addr().String(),
// TODO (TUN-3461): Update UI to show multiple origin URLs
tunnelConfig.IngressRules.CatchAll().Service.String(),
&tunnelConfig.IngressRules,
tunnelConfig.HAConnections,
)
logLevels, err := logger.ParseLevelString(c.String("loglevel"))

View File

@ -3,8 +3,10 @@ package ui
import (
"context"
"fmt"
"strings"
"time"
"github.com/cloudflare/cloudflared/ingress"
"github.com/cloudflare/cloudflared/logger"
"github.com/gdamore/tcell"
@ -34,11 +36,11 @@ type TunnelEvent struct {
}
type uiModel struct {
version string
edgeURL string
metricsURL string
proxyURL string
connections []connState
version string
edgeURL string
metricsURL string
localServices []string
connections []connState
}
type palette struct {
@ -49,13 +51,17 @@ type palette struct {
reconnecting string
}
func NewUIModel(version, hostname, metricsURL, proxyURL string, haConnections int) *uiModel {
func NewUIModel(version, hostname, metricsURL string, ing *ingress.Ingress, haConnections int) *uiModel {
localServices := make([]string, len(ing.Rules))
for i, rule := range ing.Rules {
localServices[i] = rule.Service.String()
}
return &uiModel{
version: version,
edgeURL: hostname,
metricsURL: metricsURL,
proxyURL: proxyURL,
connections: make([]connState, haConnections),
version: version,
edgeURL: hostname,
metricsURL: metricsURL,
localServices: localServices,
connections: make([]connState, haConnections),
}
}
@ -107,7 +113,8 @@ func (data *uiModel) LaunchUI(
tunnelHostText := tview.NewTextView().SetText(data.edgeURL)
grid.AddItem(tunnelHostText, 0, 1, 1, 1, 0, 0, false)
grid.AddItem(NewDynamicColorTextView().SetText(fmt.Sprintf("[%s]\u2022[%s] Proxying to [%s::b]%s", palette.connected, palette.defaultText, palette.url, data.proxyURL)), 1, 1, 1, 1, 0, 0, false)
status := fmt.Sprintf("[%s]\u2022[%s] Proxying to [%s::b]%s", palette.connected, palette.defaultText, palette.url, strings.Join(data.localServices, ", "))
grid.AddItem(NewDynamicColorTextView().SetText(status), 1, 1, 1, 1, 0, 0, false)
grid.AddItem(connTable, 2, 1, 1, 1, 0, 0, false)

View File

@ -114,13 +114,12 @@ func (ing Ingress) IsEmpty() bool {
}
// StartOrigins will start any origin services managed by cloudflared, e.g. proxy servers or Hello World.
func (ing Ingress) StartOrigins(wg *sync.WaitGroup, log logger.Service, shutdownC <-chan struct{}, errC chan error) error {
func (ing Ingress) StartOrigins(wg *sync.WaitGroup, log logger.Service, shutdownC <-chan struct{}, errC chan error) {
for _, rule := range ing.Rules {
if err := rule.Service.start(wg, log, shutdownC, errC, rule.Config); err != nil {
return err
log.Errorf("Error starting local service %s: %s", rule.Service, err)
}
}
return nil
}
// CatchAll returns the catch-all rule (i.e. the last rule)