config.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package f5cloudexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/f5cloudexporter"
  4. import (
  5. "fmt"
  6. "net/url"
  7. "os"
  8. otlphttp "go.opentelemetry.io/collector/exporter/otlphttpexporter"
  9. )
  10. // Config defines configuration for F5 Cloud exporter.
  11. type Config struct {
  12. // Config represents the OTLP HTTP Exporter configuration.
  13. otlphttp.Config `mapstructure:",squash"`
  14. // Source represents a unique identifier that is used to distinguish where this data is coming from.
  15. Source string `mapstructure:"source"`
  16. // AuthConfig represents the F5 Cloud authentication configuration options.
  17. AuthConfig AuthConfig `mapstructure:"f5cloud_auth"`
  18. }
  19. func (c *Config) sanitize() error {
  20. if len(c.Endpoint) == 0 {
  21. return fmt.Errorf("missing required \"endpoint\" setting")
  22. }
  23. endpointURL, err := url.Parse(c.Endpoint)
  24. if err != nil {
  25. return err
  26. }
  27. if len(c.Source) == 0 {
  28. return fmt.Errorf("missing required \"source\" setting")
  29. }
  30. if len(c.AuthConfig.CredentialFile) == 0 {
  31. return fmt.Errorf("missing required \"f5cloud_auth.credential_file\" setting")
  32. }
  33. if _, err := os.Stat(c.AuthConfig.CredentialFile); os.IsNotExist(err) {
  34. return fmt.Errorf("the provided \"f5cloud_auth.credential_file\" does not exist")
  35. }
  36. if len(c.AuthConfig.Audience) == 0 {
  37. c.AuthConfig.Audience = fmt.Sprintf("%s://%s", endpointURL.Scheme, endpointURL.Hostname())
  38. }
  39. return nil
  40. }
  41. // AuthConfig defines F5 Cloud authentication configurations for F5CloudAuthRoundTripper
  42. type AuthConfig struct {
  43. // CredentialFile is the F5 Cloud credentials for your designated account.
  44. CredentialFile string `mapstructure:"credential_file"`
  45. // Audience is the F5 Cloud audience for your designated account.
  46. Audience string `mapstructure:"audience"`
  47. }