config.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package swift
  2. import (
  3. "time"
  4. "github.com/imgproxy/imgproxy/v3/config"
  5. "github.com/imgproxy/imgproxy/v3/ensure"
  6. )
  7. // Config holds the configuration for Swift transport
  8. type Config struct {
  9. Username string // Username for Swift authentication
  10. APIKey string // API key for Swift authentication
  11. AuthURL string // Authentication URL for Swift
  12. Domain string // Domain for Swift authentication
  13. Tenant string // Tenant for Swift authentication
  14. AuthVersion int // Authentication version for Swift
  15. ConnectTimeout time.Duration // Connection timeout for Swift
  16. Timeout time.Duration // Request timeout for Swift
  17. }
  18. // NewDefaultConfig returns a new default configuration for Swift transport
  19. func NewDefaultConfig() Config {
  20. return Config{
  21. Username: "",
  22. APIKey: "",
  23. AuthURL: "",
  24. Domain: "",
  25. Tenant: "",
  26. AuthVersion: 0,
  27. ConnectTimeout: 10 * time.Second,
  28. Timeout: 60 * time.Second,
  29. }
  30. }
  31. // LoadConfigFromEnv loads configuration from the global config package
  32. func LoadConfigFromEnv(c *Config) (*Config, error) {
  33. c = ensure.Ensure(c, NewDefaultConfig)
  34. c.Username = config.SwiftUsername
  35. c.APIKey = config.SwiftAPIKey
  36. c.AuthURL = config.SwiftAuthURL
  37. c.Domain = config.SwiftDomain
  38. c.Tenant = config.SwiftTenant
  39. c.AuthVersion = config.SwiftAuthVersion
  40. c.ConnectTimeout = time.Duration(config.SwiftConnectTimeoutSeconds) * time.Second
  41. c.Timeout = time.Duration(config.SwiftTimeoutSeconds) * time.Second
  42. return c, nil
  43. }
  44. // Validate checks the configuration for errors
  45. func (c *Config) Validate() error {
  46. return nil
  47. }