-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
56 lines (44 loc) · 1.45 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
package aserto
import "github.com/pkg/errors"
// gRPC Client Configuration.
type Config struct {
Address string `json:"address"`
Token string `json:"token"`
TenantID string `json:"tenant_id"`
APIKey string `json:"api_key"`
ClientCertPath string `json:"client_cert_path"`
ClientKeyPath string `json:"client_key_path"`
CACertPath string `json:"ca_cert_path"`
TimeoutInSeconds int `json:"timeout_in_seconds"`
Insecure bool `json:"insecure"`
Headers map[string]string `json:"headers"`
}
func (cfg *Config) ToConnectionOptions(dop DialOptionsProvider) ([]ConnectionOption, error) {
options := []ConnectionOption{
WithInsecure(cfg.Insecure),
}
if cfg.APIKey != "" && cfg.Token != "" {
return nil, errors.New("both api_key and token are set")
}
if cfg.Token != "" {
options = append(options, WithTokenAuth(cfg.Token))
}
if cfg.APIKey != "" {
options = append(options, WithAPIKeyAuth(cfg.APIKey))
}
if cfg.Address != "" {
options = append(options, WithAddr(cfg.Address))
}
if cfg.CACertPath != "" {
options = append(options, WithCACertPath(cfg.CACertPath))
}
if cfg.TenantID != "" {
options = append(options, WithTenantID(cfg.TenantID))
}
opts, err := dop(cfg)
if err != nil {
return nil, err
}
options = append(options, WithDialOptions(opts...))
return options, nil
}