-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
52 lines (43 loc) · 1.38 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
package databricks
import (
"encoding/json"
"time"
"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/sshtunnel"
)
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
Path string `json:"path"`
Token string `json:"token"`
Catalog string `json:"catalog"`
Schema string `json:"schema"`
TunnelInfo *sshtunnel.Config `json:"tunnel_info,omitempty"`
RetryAttempts int `json:"retryAttempts"` // default: 4
MinRetryWaitTime time.Duration `json:"minRetryWaitTime"` // default: 1s
MaxRetryWaitTime time.Duration `json:"maxRetryWaitTime"` // default: 30s
MaxConnIdleTime time.Duration `json:"maxConnIdleTime"` // default: disabled
Timeout time.Duration `json:"timeout"` // default: no timeout
SessionParams map[string]string `json:"sessionParams"`
UseLegacyMappings bool `json:"useLegacyMappings"`
}
func (c *Config) Parse(input json.RawMessage) error {
err := json.Unmarshal(input, c)
if err != nil {
return err
}
if c.TunnelInfo == nil { // if tunnel info is not provided as a separate json object, try to parse it from the input
if c.TunnelInfo, err = sshtunnel.ParseInlineConfig(input); err != nil {
return err
}
}
if c.RetryAttempts == 0 {
c.RetryAttempts = 4
}
if c.MinRetryWaitTime == 0 {
c.MinRetryWaitTime = 1 * time.Second
}
if c.MaxRetryWaitTime == 0 {
c.MaxRetryWaitTime = 30 * time.Second
}
return nil
}