config.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package solacereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver"
  4. import (
  5. "errors"
  6. "strings"
  7. "time"
  8. "go.opentelemetry.io/collector/config/configopaque"
  9. "go.opentelemetry.io/collector/config/configtls"
  10. )
  11. const (
  12. // 8Kb
  13. saslMaxInitFrameSizeOverride = 8000
  14. )
  15. var (
  16. errMissingAuthDetails = errors.New("authentication details are required, either for plain user name password or XOAUTH2 or client certificate")
  17. errMissingQueueName = errors.New("queue definition is required, queue definition has format queue://<queuename>")
  18. errMissingPlainTextParams = errors.New("missing plain text auth params: Username, Password")
  19. errMissingXauth2Params = errors.New("missing xauth2 text auth params: Username, Bearer")
  20. errMissingFlowControl = errors.New("missing flow control configuration: DelayedRetry must be selected")
  21. errInvalidDelayedRetryDelay = errors.New("delayed_retry.delay must > 0")
  22. )
  23. // Config defines configuration for Solace receiver.
  24. type Config struct {
  25. // The list of solace brokers (default localhost:5671)
  26. Broker []string `mapstructure:"broker"`
  27. // The name of the solace queue to consume from, it is required parameter
  28. Queue string `mapstructure:"queue"`
  29. // The maximum number of unacknowledged messages the Solace broker can transmit, to configure AMQP Link
  30. MaxUnacked int32 `mapstructure:"max_unacknowledged"`
  31. TLS configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
  32. Auth Authentication `mapstructure:"auth"`
  33. Flow FlowControl `mapstructure:"flow_control"`
  34. }
  35. // Validate checks the receiver configuration is valid
  36. func (cfg *Config) Validate() error {
  37. if cfg.Auth.PlainText == nil && cfg.Auth.External == nil && cfg.Auth.XAuth2 == nil {
  38. return errMissingAuthDetails
  39. }
  40. if len(strings.TrimSpace(cfg.Queue)) == 0 {
  41. return errMissingQueueName
  42. }
  43. if cfg.Flow.DelayedRetry == nil {
  44. return errMissingFlowControl
  45. } else if cfg.Flow.DelayedRetry.Delay <= 0 {
  46. return errInvalidDelayedRetryDelay
  47. }
  48. return nil
  49. }
  50. // Authentication defines authentication strategies.
  51. type Authentication struct {
  52. PlainText *SaslPlainTextConfig `mapstructure:"sasl_plain"`
  53. XAuth2 *SaslXAuth2Config `mapstructure:"sasl_xauth2"`
  54. External *SaslExternalConfig `mapstructure:"sasl_external"`
  55. }
  56. // SaslPlainTextConfig defines SASL PLAIN authentication.
  57. type SaslPlainTextConfig struct {
  58. Username string `mapstructure:"username"`
  59. Password configopaque.String `mapstructure:"password"`
  60. }
  61. // SaslXAuth2Config defines the configuration for the SASL XAUTH2 authentication.
  62. type SaslXAuth2Config struct {
  63. Username string `mapstructure:"username"`
  64. Bearer string `mapstructure:"bearer"`
  65. }
  66. // SaslExternalConfig defines the configuration for the SASL External used in conjunction with TLS client authentication.
  67. type SaslExternalConfig struct {
  68. }
  69. // FlowControl defines the configuration for what to do in backpressure scenarios, e.g. memorylimiter errors
  70. type FlowControl struct {
  71. DelayedRetry *FlowControlDelayedRetry `mapstructure:"delayed_retry"`
  72. }
  73. // FlowControlDelayedRetry represents the strategy of waiting for a defined amount of time (in time.Duration) and attempt redelivery
  74. type FlowControlDelayedRetry struct {
  75. Delay time.Duration `mapstructure:"delay"`
  76. }