Skip to content

Commit f6bf0ff

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 3543703 commit f6bf0ff

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ type TSApp struct {
2222
// DefaultAuthKey is the default auth key to use for Tailscale if no other auth key is specified.
2323
DefaultAuthKey string `json:"auth_key,omitempty" caddy:"namespace=tailscale.auth_key"`
2424

25+
// ControlURL specifies the default control URL to use for nodes.
26+
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`
27+
2528
// Ephemeral specifies whether Tailscale nodes should be registered as ephemeral.
2629
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`
2730

@@ -38,6 +41,9 @@ type TSNode struct {
3841
// AuthKey is the Tailscale auth key used to register the node.
3942
AuthKey string `json:"auth_key,omitempty" caddy:"namespace=auth_key"`
4043

44+
// ControlURL specifies the control URL to use for the node.
45+
ControlURL string `json:"control_url,omitempty" caddy:"namespace=tailscale.control_url"`
46+
4147
// Ephemeral specifies whether the node should be registered as ephemeral.
4248
Ephemeral bool `json:"ephemeral,omitempty" caddy:"namespace=tailscale.ephemeral"`
4349

@@ -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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ func getNode(ctx caddy.Context, name string) (*tailscaleNode, error) {
111111
}
112112

113113
if s.AuthKey, err = getAuthKey(name, app); err != nil {
114-
app.logger.Warn("error parsing auth key", zap.Error(err))
114+
return nil, err
115+
}
116+
if s.ControlURL, err = getControlURL(name, app); err != nil {
117+
return nil, err
115118
}
116119

117120
if name != "" {
@@ -167,6 +170,19 @@ func getAuthKey(name string, app *TSApp) (string, error) {
167170
return os.Getenv("TS_AUTHKEY"), nil
168171
}
169172

173+
func getControlURL(name string, app *TSApp) (string, error) {
174+
if app == nil {
175+
return "", nil
176+
}
177+
if node, ok := app.Nodes[name]; ok {
178+
if node.ControlURL != "" {
179+
return repl.ReplaceOrErr(node.ControlURL, true, true)
180+
}
181+
}
182+
183+
return repl.ReplaceOrErr(app.ControlURL, true, true)
184+
}
185+
170186
func getEphemeral(name string, app *TSApp) bool {
171187
if app == nil {
172188
return false

0 commit comments

Comments
 (0)