-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
66 lines (61 loc) · 2.49 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
package filemanager
import (
"os"
"github.com/rudderlabs/rudder-go-kit/config"
)
type ProviderConfigOpts struct {
Provider string
Bucket string
Prefix string
Config *config.Config
ExternalIDSupplier func() string
}
func GetProviderConfigFromEnv(opts ProviderConfigOpts) map[string]interface{} {
if opts.Config == nil {
opts.Config = config.Default
}
if opts.ExternalIDSupplier == nil {
opts.ExternalIDSupplier = func() string { return "" }
}
config := opts.Config
providerConfig := make(map[string]interface{})
switch opts.Provider {
case "S3":
providerConfig["bucketName"] = opts.Bucket
providerConfig["prefix"] = opts.Prefix
providerConfig["accessKeyID"] = config.GetString("AWS_ACCESS_KEY_ID", "")
providerConfig["accessKey"] = config.GetString("AWS_SECRET_ACCESS_KEY", "")
providerConfig["enableSSE"] = config.GetBool("AWS_ENABLE_SSE", false)
providerConfig["regionHint"] = config.GetString("AWS_S3_REGION_HINT", "us-east-1")
providerConfig["iamRoleArn"] = config.GetString("BACKUP_IAM_ROLE_ARN", "")
if providerConfig["iamRoleArn"] != "" {
providerConfig["externalID"] = opts.ExternalIDSupplier()
}
case "GCS":
providerConfig["bucketName"] = opts.Bucket
providerConfig["prefix"] = opts.Prefix
credentials, err := os.ReadFile(config.GetString("GOOGLE_APPLICATION_CREDENTIALS", ""))
if err == nil {
providerConfig["credentials"] = string(credentials)
}
case "AZURE_BLOB":
providerConfig["containerName"] = opts.Bucket
providerConfig["prefix"] = opts.Prefix
providerConfig["accountName"] = config.GetString("AZURE_STORAGE_ACCOUNT", "")
providerConfig["accountKey"] = config.GetString("AZURE_STORAGE_ACCESS_KEY", "")
case "MINIO":
providerConfig["bucketName"] = opts.Bucket
providerConfig["prefix"] = opts.Prefix
providerConfig["endPoint"] = config.GetString("MINIO_ENDPOINT", "localhost:9000")
providerConfig["accessKeyID"] = config.GetString("MINIO_ACCESS_KEY_ID", "minioadmin")
providerConfig["secretAccessKey"] = config.GetString("MINIO_SECRET_ACCESS_KEY", "minioadmin")
providerConfig["useSSL"] = config.GetBool("MINIO_SSL", false)
case "DIGITAL_OCEAN_SPACES":
providerConfig["bucketName"] = opts.Bucket
providerConfig["prefix"] = opts.Prefix
providerConfig["endPoint"] = config.GetString("DO_SPACES_ENDPOINT", "")
providerConfig["accessKeyID"] = config.GetString("DO_SPACES_ACCESS_KEY_ID", "")
providerConfig["accessKey"] = config.GetString("DO_SPACES_SECRET_ACCESS_KEY", "")
}
return providerConfig
}