forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
60 lines (48 loc) · 1.59 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package cloudflarereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/cloudflarereceiver"
import (
"errors"
"fmt"
"net"
"go.opentelemetry.io/collector/config/configtls"
"go.uber.org/multierr"
)
// Config holds all the parameters to start an HTTP server that can be sent logs from CloudFlare
type Config struct {
Logs LogsConfig `mapstructure:"logs"`
}
type LogsConfig struct {
Secret string `mapstructure:"secret"`
Endpoint string `mapstructure:"endpoint"`
TLS *configtls.ServerConfig `mapstructure:"tls"`
Attributes map[string]string `mapstructure:"attributes"`
TimestampField string `mapstructure:"timestamp_field"`
}
var (
errNoEndpoint = errors.New("an endpoint must be specified")
errNoCert = errors.New("tls was configured, but no cert file was specified")
errNoKey = errors.New("tls was configured, but no key file was specified")
defaultTimestampField = "EdgeStartTimestamp"
)
func (c *Config) Validate() error {
if c.Logs.Endpoint == "" {
return errNoEndpoint
}
var errs error
if c.Logs.TLS != nil {
// Missing key
if c.Logs.TLS.KeyFile == "" {
errs = multierr.Append(errs, errNoKey)
}
// Missing cert
if c.Logs.TLS.CertFile == "" {
errs = multierr.Append(errs, errNoCert)
}
}
_, _, err := net.SplitHostPort(c.Logs.Endpoint)
if err != nil {
errs = multierr.Append(errs, fmt.Errorf("failed to split endpoint into 'host:port' pair: %w", err))
}
return errs
}