config.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package s3
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/config"
  4. "github.com/imgproxy/imgproxy/v3/ensure"
  5. )
  6. // Config holds the configuration for S3 transport
  7. type Config struct {
  8. Region string // AWS region for S3 (default: "")
  9. Endpoint string // Custom endpoint for S3 (default: "")
  10. EndpointUsePathStyle bool // Use path-style URLs for S3 (default: true)
  11. AssumeRoleArn string // ARN for assuming an AWS role (default: "")
  12. AssumeRoleExternalID string // External ID for assuming an AWS role (default: "")
  13. DecryptionClientEnabled bool // Enables S3 decryption client (default: false)
  14. }
  15. // NewDefaultConfig returns a new default configuration for S3 transport
  16. func NewDefaultConfig() Config {
  17. return Config{
  18. Region: "",
  19. Endpoint: "",
  20. EndpointUsePathStyle: true,
  21. AssumeRoleArn: "",
  22. AssumeRoleExternalID: "",
  23. DecryptionClientEnabled: false,
  24. }
  25. }
  26. // LoadConfigFromEnv loads configuration from the global config package
  27. func LoadConfigFromEnv(c *Config) (*Config, error) {
  28. c = ensure.Ensure(c, NewDefaultConfig)
  29. c.Region = config.S3Region
  30. c.Endpoint = config.S3Endpoint
  31. c.EndpointUsePathStyle = config.S3EndpointUsePathStyle
  32. c.AssumeRoleArn = config.S3AssumeRoleArn
  33. c.AssumeRoleExternalID = config.S3AssumeRoleExternalID
  34. c.DecryptionClientEnabled = config.S3DecryptionClientEnabled
  35. return c, nil
  36. }
  37. // Validate checks the configuration for errors
  38. func (c *Config) Validate() error {
  39. return nil
  40. }