-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
74 lines (61 loc) · 2.15 KB
/
Copy pathoptions.go
File metadata and controls
74 lines (61 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-FileCopyrightText: 2026 Adriano Sela Aviles (@adrianosela)
// SPDX-License-Identifier: MIT
package tsdmg
import (
"errors"
"fmt"
"net/url"
"github.com/adrianosela/tsdmg/pkg/logger"
"tailscale.com/client/local"
)
var (
errNilLogger = errors.New("logger must not be nil")
errEmptyServerURL = errors.New("serverURL must not be empty")
errInvalidServerURL = errors.New("serverURL is not a valid URL")
errClientClosed = errors.New("client is closed")
)
type config struct {
logger logger.Logger
serverURL string
skipTailscaleNode bool
tailscaleClient *local.Client
}
func (c *config) validate() error {
if c.logger == nil {
return errNilLogger
}
if c.serverURL == "" {
return errEmptyServerURL
}
if _, err := url.Parse(c.serverURL); err != nil {
return fmt.Errorf("%w: %v", errInvalidServerURL, err)
}
return nil
}
// Option represents a configuration option for initializing a client.
type Option func(*config)
// WithLogger is a configuration option to configure a logger.
// If this option is not set a log/slog logger is used with a
// JSON handler.
func WithLogger(logger logger.Logger) Option {
return func(c *config) { c.logger = logger }
}
// WithSkipTailscaleNode is a configuration option to signal
// that the client is an existing Tailscale node, with networking
// already set-up. When this option is set, the client will skip
// initializing an underlying tsnet Tailscale node, and instead
// will rely on the machine's networking allowing it to reach the
// certsnet server a.k.a. acme proxy.
func WithSkipTailscaleNode(skipTailscaleNode bool) Option {
return func(c *config) { c.skipTailscaleNode = skipTailscaleNode }
}
// WithTailscaleNode is a configuration option to pass an already
// initialized Tailscale (tsnet) client to be used for making
// requests to the certnet server a.k.a. acme proxy.
//
// If WithTailscaleNode and WithSkipTailscaleNode are BOTH unset,
// the client will attempt to initialize a new, ephemeral, tsnet
// Tailscale node. For that to succeed, TS_AUTHKEY env must be set.
func WithTailscaleNode(tailscaleClient *local.Client) Option {
return func(c *config) { c.tailscaleClient = tailscaleClient }
}