config.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package snowflakereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/snowflakereceiver"
  4. import (
  5. "errors"
  6. "go.opentelemetry.io/collector/config/configopaque"
  7. "go.opentelemetry.io/collector/receiver/scraperhelper"
  8. "go.uber.org/multierr"
  9. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/snowflakereceiver/internal/metadata"
  10. )
  11. var (
  12. errMissingUsername = errors.New("You must provide a valid snowflake username")
  13. errMissingPassword = errors.New("You must provide a password for the snowflake username")
  14. errMissingAccount = errors.New("You must provide a valid account name")
  15. errMissingWarehouse = errors.New("You must provide a valid warehouse name")
  16. )
  17. type Config struct {
  18. scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
  19. metadata.MetricsBuilderConfig `mapstructure:",squash"`
  20. Username string `mapstructure:"username"`
  21. Password configopaque.String `mapstructure:"password"`
  22. Account string `mapstructure:"account"`
  23. Schema string `mapstructure:"schema"`
  24. Warehouse string `mapstructure:"warehouse"`
  25. Database string `mapstructure:"database"`
  26. Role string `mapstructure:"role"`
  27. }
  28. func (cfg *Config) Validate() error {
  29. var errs error
  30. if cfg.Username == "" {
  31. errs = multierr.Append(errs, errMissingUsername)
  32. }
  33. if cfg.Password == "" {
  34. errs = multierr.Append(errs, errMissingPassword)
  35. }
  36. if cfg.Account == "" {
  37. errs = multierr.Append(errs, errMissingAccount)
  38. }
  39. if cfg.Warehouse == "" {
  40. errs = multierr.Append(errs, errMissingWarehouse)
  41. }
  42. return errs
  43. }