-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
90 lines (72 loc) · 2.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package tell
import (
"crypto/tls"
"time"
"github.com/twmb/tlscfg"
)
type Config struct {
// Collector to show URL of grpc otel collector.
// If emptry disable for metric and trace. It is add a noop metric/trace and your code works without change.
Collector string `cfg:"collector"`
TLS TLSConfig `cfg:"tls"`
// ServerName sets the grpc.WithAuthority with extract host(server_name) for connection.
ServerName string `cfg:"server_name"`
Metric MetricSettings `cfg:"metric"`
Trace TraceSettings `cfg:"trace"`
Logger Logger `cfg:"-"`
}
type TLSConfig struct {
Enabled bool `cfg:"enabled"`
InsecureSkipVerify bool `cfg:"insecure_skip_verify"`
// CertFile is the path to the client's TLS certificate.
// Should be use with KeyFile.
CertFile string `cfg:"cert_file"`
// KeyFile is the path to the client's TLS key.
// Should be use with CertFile.
KeyFile string `cfg:"key_file"`
// CAFile is the path to the CA certificate.
// If empty, the server's root CA set will be used.
CAFile string `cfg:"ca_file"`
}
// Generate returns a tls.Config based on the TLSConfig.
//
// If the TLSConfig is not enabled, nil is returned.
func (t TLSConfig) Generate() (*tls.Config, error) {
if !t.Enabled {
return nil, nil
}
opts := []tlscfg.Opt{}
// load client cert
if t.CertFile != "" && t.KeyFile != "" {
opts = append(opts, tlscfg.WithDiskKeyPair(t.CertFile, t.KeyFile))
}
// load CA cert
opts = append(opts, tlscfg.WithSystemCertPool())
if t.CAFile != "" {
opts = append(opts, tlscfg.WithDiskCA(t.CAFile, tlscfg.ForClient))
}
cfg, err := tlscfg.New(opts...)
if err != nil {
return nil, err
}
if t.InsecureSkipVerify {
cfg.InsecureSkipVerify = true
}
return cfg, nil
}
type MetricSettings struct {
Provider MetricProviderSettings `cfg:"provider"`
Disable bool `cfg:"disable"`
Default MetricDefault `cfg:"default"`
}
type MetricDefault struct {
GoRuntime bool `cfg:"go_runtime"`
}
type MetricProviderSettings struct {
Interval time.Duration `cfg:"interval"`
}
type TraceSettings struct {
Provider TraceProviderSettings `cfg:"provider"`
Disable bool `cfg:"disable"`
}
type TraceProviderSettings struct{}