forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
77 lines (61 loc) · 2.09 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package cloudfoundryreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/cloudfoundryreceiver"
import (
"errors"
"fmt"
"net/url"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
)
type RLPGatewayConfig struct {
confighttp.ClientConfig `mapstructure:",squash"`
ShardID string `mapstructure:"shard_id"`
}
// LimitedTLSClientSetting is a subset of TLSClientSetting, see LimitedClientConfig for more details
type LimitedTLSClientSetting struct {
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
}
// LimitedClientConfig is a subset of ClientConfig, implemented as a separate type due to the library this
// configuration is used with not taking a preconfigured http.Client as input, but only taking these specific options
type LimitedClientConfig struct {
Endpoint string `mapstructure:"endpoint"`
TLSSetting LimitedTLSClientSetting `mapstructure:"tls"`
}
type UAAConfig struct {
LimitedClientConfig `mapstructure:",squash"`
Username string `mapstructure:"username"`
Password configopaque.String `mapstructure:"password"`
}
// Config defines configuration for Collectd receiver.
type Config struct {
RLPGateway RLPGatewayConfig `mapstructure:"rlp_gateway"`
UAA UAAConfig `mapstructure:"uaa"`
}
func (c *Config) Validate() error {
err := validateURLOption("rlp_gateway.endpoint", c.RLPGateway.Endpoint)
if err != nil {
return err
}
err = validateURLOption("uaa.endpoint", c.UAA.Endpoint)
if err != nil {
return err
}
if c.UAA.Username == "" {
return errors.New("UAA username not specified")
}
if c.UAA.Password == "" {
return errors.New("UAA password not specified")
}
return nil
}
func validateURLOption(name string, value string) error {
if value == "" {
return fmt.Errorf("%s not specified", name)
}
_, err := url.Parse(value)
if err != nil {
return fmt.Errorf("failed to parse %s as url: %w", name, err)
}
return nil
}