Skip to content

Commit 8b9aa03

Browse files
willnorrisChibangLW
andcommitted
add config option for control URL
Closes #22 Co-authored-by: ChibangLW <ich@leonlenzen.de> Signed-off-by: Will Norris <will@tailscale.com>
1 parent 27fad94 commit 8b9aa03

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type TSApp struct {
2525
// Ephemeral specifies whether Tailscale nodes should be registered as ephemeral.
2626
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`
2727

28+
// ControlURL specifies the default control URL to use for nodes.
29+
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`
30+
2831
// Nodes is a map of per-node configuration which overrides global options.
2932
Nodes map[string]TSNode `json:"nodes,omitempty" caddy:"namespace=tailscale"`
3033

@@ -41,6 +44,9 @@ type TSNode struct {
4144
// Ephemeral specifies whether the node should be registered as ephemeral.
4245
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`
4346

47+
// ControlURL specifies the control URL to use for the node.
48+
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`
49+
4450
name string
4551
}
4652

@@ -119,6 +125,11 @@ func parseTSNode(d *caddyfile.Dispenser) (TSNode, error) {
119125
return node, segment.ArgErr()
120126
}
121127
node.AuthKey = segment.Val()
128+
case "control_url":
129+
if !segment.NextArg() {
130+
return node, segment.ArgErr()
131+
}
132+
node.ControlURL = segment.Val()
122133
case "ephemeral":
123134
node.Ephemeral = true
124135
default:

module.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ func getNode(ctx caddy.Context, name string) (*tailscaleNode, error) {
114114
if s.AuthKey, err = getAuthKey(name, app); err != nil {
115115
app.logger.Warn("error parsing auth key", zap.Error(err))
116116
}
117+
if s.ControlURL, err = getControlURL(name, app); err != nil {
118+
app.logger.Warn("error parsing control URL", zap.Error(err))
119+
}
117120

118121
if name != "" {
119122
// Set config directory for tsnet. By default, tsnet will use the name of the
@@ -179,6 +182,19 @@ func getEphemeral(name string, app *TSApp) bool {
179182
return app.Ephemeral
180183
}
181184

185+
func getControlURL(name string, app *TSApp) (string, error) {
186+
if app == nil {
187+
return "", nil
188+
}
189+
if node, ok := app.Nodes[name]; ok {
190+
if node.ControlURL != "" {
191+
return repl.ReplaceOrErr(node.ControlURL, true, true)
192+
}
193+
}
194+
195+
return repl.ReplaceOrErr(app.ControlURL, true, true)
196+
}
197+
182198
// tailscaleNode is a wrapper around a tsnet.Server that provides a fully self-contained Tailscale node.
183199
// This node can listen on the tailscale network interface, or be used to connect to other nodes in the tailnet.
184200
type tailscaleNode struct {

0 commit comments

Comments
 (0)