// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package rabbitmqreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver" import ( "errors" "fmt" "net/url" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/receiver/scraperhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver/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 ://:`) ) const defaultEndpoint = "http://localhost:15672" // Config defines the configuration for the various elements of the receiver agent. type Config struct { scraperhelper.ScraperControllerSettings `mapstructure:",squash"` confighttp.ClientConfig `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 = append(err, errMissingUsername) } if cfg.Password == "" { err = append(err, errMissingPassword) } _, parseErr := url.Parse(cfg.Endpoint) if parseErr != nil { wrappedErr := fmt.Errorf("%s: %w", errInvalidEndpoint.Error(), parseErr) err = append(err, wrappedErr) } return errors.Join(err...) }