-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.go
76 lines (67 loc) · 1.98 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
75
76
package s3
import (
"fmt"
"strings"
"github.com/kubemq-io/kubemq-sources/config"
)
var bucketTypeMap = map[string]string{
"aws": "aws",
"gcp": "gcp",
"minio": "minio",
"filesystem": "filesystem",
"hdfs": "hdfs",
"azure": "azure",
"pass-through": "pass-through",
}
type options struct {
awsKey string
awsSecretKey string
region string
token string
folders []string
concurrency int
targetType string
bucketName string
scanInterval int
}
func parseOptions(cfg config.Spec) (options, error) {
o := options{}
var err error
o.awsKey, err = cfg.Properties.MustParseString("aws_key")
if err != nil {
return options{}, fmt.Errorf("error parsing aws_key , %w", err)
}
o.awsSecretKey, err = cfg.Properties.MustParseString("aws_secret_key")
if err != nil {
return options{}, fmt.Errorf("error parsing aws_secret_key , %w", err)
}
o.region, err = cfg.Properties.MustParseString("region")
if err != nil {
return options{}, fmt.Errorf("error parsing region , %w", err)
}
o.token = cfg.Properties.ParseString("token", "")
o.folders, err = cfg.Properties.MustParseStringList("folders")
if err != nil {
return options{}, fmt.Errorf("error parsing folders, %w", err)
}
o.targetType, err = cfg.Properties.ParseStringMap("target_type", bucketTypeMap)
if err != nil {
return options{}, fmt.Errorf("error parsing target_type, %w", err)
}
o.bucketName, err = cfg.Properties.MustParseString("bucket_name")
if err != nil {
return options{}, fmt.Errorf("error parsing bucket_name, %w", err)
}
o.concurrency, err = cfg.Properties.ParseIntWithRange("concurrency", 1, 1, 1024)
if err != nil {
return options{}, fmt.Errorf("error parsing concurrency")
}
o.scanInterval, err = cfg.Properties.ParseIntWithRange("scan_interval", 5, 1, 3600*365)
if err != nil {
return options{}, fmt.Errorf("error parsing scan_interval")
}
return o, nil
}
func unixNormalize(in string) string {
return strings.Replace(in, `\`, "/", -1)
}