/
config.go
93 lines (77 loc) · 2.31 KB
/
config.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package controller
import "time"
// Option configures a controller.
type Option func(*controllerConfig)
type controllerConfig struct {
apiToken string
clusterAPIEndpoint string
connectAPIEndpoint string
otelEndpoint string
tmpDir string
bootstrapConfigFileName string
reconcilerLeaseDuration time.Duration
databrokerRequestTimeout time.Duration
}
// WithTmpDir sets the temporary directory to use.
func WithTmpDir(dir string) Option {
return func(c *controllerConfig) {
c.tmpDir = dir
}
}
// WithClusterAPIEndpoint sets the endpoint to use for the cluster API
func WithClusterAPIEndpoint(endpoint string) Option {
return func(c *controllerConfig) {
c.clusterAPIEndpoint = endpoint
}
}
// WithConnectAPIEndpoint sets the endpoint to use for the connect API
func WithConnectAPIEndpoint(endpoint string) Option {
return func(c *controllerConfig) {
c.connectAPIEndpoint = endpoint
}
}
// WithOTELAPIEndpoint sets the endpoint to use for the OTEL API
func WithOTELAPIEndpoint(endpoint string) Option {
return func(c *controllerConfig) {
c.otelEndpoint = endpoint
}
}
// WithAPIToken sets the API token to use for authentication.
func WithAPIToken(token string) Option {
return func(c *controllerConfig) {
c.apiToken = token
}
}
// WithBootstrapConfigFileName sets the name of the file to store the bootstrap config in.
func WithBootstrapConfigFileName(name string) Option {
return func(c *controllerConfig) {
c.bootstrapConfigFileName = name
}
}
// WithDatabrokerLeaseDuration sets the lease duration for the
func WithDatabrokerLeaseDuration(duration time.Duration) Option {
return func(c *controllerConfig) {
c.reconcilerLeaseDuration = duration
}
}
// WithDatabrokerRequestTimeout sets the timeout for databroker requests.
func WithDatabrokerRequestTimeout(timeout time.Duration) Option {
return func(c *controllerConfig) {
c.databrokerRequestTimeout = timeout
}
}
func newControllerConfig(opts ...Option) *controllerConfig {
c := new(controllerConfig)
for _, opt := range []Option{
WithClusterAPIEndpoint("https://console.pomerium.com/cluster/v1"),
WithConnectAPIEndpoint("https://connect.pomerium.com"),
WithDatabrokerLeaseDuration(time.Second * 30),
WithDatabrokerRequestTimeout(time.Second * 30),
} {
opt(c)
}
for _, opt := range opts {
opt(c)
}
return c
}