Skip to content

Commit 9fa40cb

Browse files
willnorrisChibangLW
andcommitted
add config option for control URL
also return any replacer errors, and remove app nil check since we always check prior to calling these config funcs. Closes #22 Co-authored-by: ChibangLW <ich@leonlenzen.de> Signed-off-by: Will Norris <will@tailscale.com>
1 parent 3543703 commit 9fa40cb

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
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: 13 additions & 9 deletions
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 != "" {
@@ -142,10 +145,6 @@ func getNode(ctx caddy.Context, name string) (*tailscaleNode, error) {
142145
var repl = caddy.NewReplacer()
143146

144147
func getAuthKey(name string, app *TSApp) (string, error) {
145-
if app == nil {
146-
return "", nil
147-
}
148-
149148
if node, ok := app.Nodes[name]; ok {
150149
if node.AuthKey != "" {
151150
return repl.ReplaceOrErr(node.AuthKey, true, true)
@@ -167,14 +166,19 @@ func getAuthKey(name string, app *TSApp) (string, error) {
167166
return os.Getenv("TS_AUTHKEY"), nil
168167
}
169168

170-
func getEphemeral(name string, app *TSApp) bool {
171-
if app == nil {
172-
return false
169+
func getControlURL(name string, app *TSApp) (string, error) {
170+
if node, ok := app.Nodes[name]; ok {
171+
if node.ControlURL != "" {
172+
return repl.ReplaceOrErr(node.ControlURL, true, true)
173+
}
173174
}
175+
return repl.ReplaceOrErr(app.ControlURL, true, true)
176+
}
177+
178+
func getEphemeral(name string, app *TSApp) bool {
174179
if node, ok := app.Nodes[name]; ok {
175180
return node.Ephemeral
176181
}
177-
178182
return app.Ephemeral
179183
}
180184

0 commit comments

Comments
 (0)