/
opts.go
104 lines (89 loc) · 2.5 KB
/
opts.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
94
95
96
97
98
99
100
101
102
103
104
package logcollector
import (
"net/http"
"net/url"
"github.com/digital-dream-labs/vector-cloud/internal/token"
"github.com/digital-dream-labs/vector-cloud/internal/util"
)
type options struct {
server bool
socketNameSuffix string
tokener token.Accessor
httpClient *http.Client
errListener util.ErrorListener
bucketName string
s3BasePrefix string
awsRegion string
endpoint string
s3ForcePathStyle bool
disableSSL bool
}
// Option defines an option that can be set on the server
type Option func(o *options)
// WithServer specifies that an IPC server should be started so other processes
// can use log collection
func WithServer() Option {
return func(o *options) {
o.server = true
}
}
// WithSocketNameSuffix specifies the (optional) suffix of the socket name
func WithSocketNameSuffix(socketNameSuffix string) Option {
return func(o *options) {
o.socketNameSuffix = socketNameSuffix
}
}
// WithHTTPClient specifies the HTTP client to use
func WithHTTPClient(httpClient *http.Client) Option {
return func(o *options) {
o.httpClient = httpClient
}
}
// WithTokener specifies that the given token.Accessor should be used to obtain
// authorization credentials (used to retrieve USerID)
func WithTokener(value token.Accessor) Option {
return func(o *options) {
o.tokener = value
}
}
// WithEndpoint specifies the S3 endpoint
func WithEndpoint(endpoint string) Option {
return func(o *options) {
o.endpoint = endpoint
}
}
// WithS3ForcePathStyle sets whether path style needs to be forced
func WithS3ForcePathStyle(s3ForcePathStyle bool) Option {
return func(o *options) {
o.s3ForcePathStyle = s3ForcePathStyle
}
}
// WithDisableSSL sets whether SSL is used to access the cloud
func WithDisableSSL(disableSSL bool) Option {
return func(o *options) {
o.disableSSL = disableSSL
}
}
// WithS3UrlPrefix specifies the S3 bucket and key prefix in the cloud
// E.g. s3://anki-device-logs-dev/victor
func WithS3UrlPrefix(s3UrlPrefix string) Option {
return func(o *options) {
parsedURL, err := url.Parse(s3UrlPrefix)
if err == nil {
o.bucketName = parsedURL.Host
o.s3BasePrefix = parsedURL.Path
}
}
}
// WithAwsRegion specifies the AWS region
func WithAwsRegion(awsRegion string) Option {
return func(o *options) {
o.awsRegion = awsRegion
}
}
// WithErrorListener reports errors to the specified error listener
func WithErrorListener(errListener util.ErrorListener) Option {
return func(o *options) {
o.errListener = errListener
}
}