12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package bigipreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigipreceiver"
- import (
- "errors"
- "fmt"
- "net/url"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/config/configopaque"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "go.uber.org/multierr"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigipreceiver/internal/metadata"
- )
- // Predefined error responses for configuration validation failures
- var (
- errMissingUsername = errors.New(`"username" not specified in config`)
- errMissingPassword = errors.New(`"password" not specified in config`)
- errInvalidEndpoint = errors.New(`"endpoint" must be in the form of <scheme>://<hostname>:<port>`)
- )
- const defaultEndpoint = "https://localhost:443"
- // Config defines the configuration for the various elements of the receiver agent.
- type Config struct {
- scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
- confighttp.HTTPClientSettings `mapstructure:",squash"`
- Username string `mapstructure:"username"`
- Password configopaque.String `mapstructure:"password"`
- metadata.MetricsBuilderConfig `mapstructure:",squash"`
- }
- // Validate validates the configuration by checking for missing or invalid fields
- func (cfg *Config) Validate() error {
- var err error
- if cfg.Username == "" {
- err = multierr.Append(err, errMissingUsername)
- }
- if cfg.Password == "" {
- err = multierr.Append(err, errMissingPassword)
- }
- _, parseErr := url.Parse(cfg.Endpoint)
- if parseErr != nil {
- wrappedErr := fmt.Errorf("%s: %w", errInvalidEndpoint.Error(), parseErr)
- err = multierr.Append(err, wrappedErr)
- }
- return err
- }
|