-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
74 lines (60 loc) · 1.67 KB
/
options.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
package cpsdk
import (
"fmt"
"net/url"
"time"
"github.com/rudderlabs/rudder-go-kit/logger"
"github.com/rudderlabs/rudder-cp-sdk/identity"
)
type Option func(*ControlPlane) error
var ErrIdentityMutuallyExclusive = fmt.Errorf("cannot set both workspace and namespace identity")
func WithWorkspaceIdentity(workspaceToken string) Option {
return func(cp *ControlPlane) error {
if cp.namespaceIdentity != nil {
return ErrIdentityMutuallyExclusive
}
cp.workspaceIdentity = &identity.Workspace{WorkspaceToken: workspaceToken}
return nil
}
}
func WithNamespaceIdentity(namespace, secret string) Option {
return func(cp *ControlPlane) error {
if cp.workspaceIdentity != nil {
return ErrIdentityMutuallyExclusive
}
cp.namespaceIdentity = &identity.Namespace{Namespace: namespace, Secret: secret}
return nil
}
}
func WithBaseUrl(baseUrl string) Option {
return func(cp *ControlPlane) error {
url, err := url.Parse(baseUrl)
if err != nil {
return fmt.Errorf("invalid base url: %w", err)
}
cp.baseUrl = url
cp.baseUrlV2 = url
return nil
}
}
func WithAdminCredentials(credentials *identity.AdminCredentials) Option {
return func(cp *ControlPlane) error {
cp.adminCredentials = credentials
return nil
}
}
func WithLogger(log logger.Logger) Option {
return func(cp *ControlPlane) error {
cp.log = log
return nil
}
}
// WithPollingInterval sets the interval at which the SDK polls for new configs.
// If not set, the SDK will poll every 1 second.
// If set to 0, the SDK will not poll for new configs.
func WithPollingInterval(interval time.Duration) Option {
return func(cp *ControlPlane) error {
cp.pollingInterval = interval
return nil
}
}