1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-12-09 09:56:01 +02:00
imgproxy/config/config.go

705 lines
21 KiB
Go
Raw Normal View History

2021-04-26 13:52:50 +02:00
package config
import (
"errors"
2021-04-26 13:52:50 +02:00
"flag"
"fmt"
"math"
"os"
2021-09-07 15:04:33 +02:00
"regexp"
2021-04-26 13:52:50 +02:00
"runtime"
log "github.com/sirupsen/logrus"
2021-09-30 16:23:30 +02:00
"github.com/imgproxy/imgproxy/v3/config/configurators"
"github.com/imgproxy/imgproxy/v3/imagetype"
"github.com/imgproxy/imgproxy/v3/version"
2021-04-26 13:52:50 +02:00
)
var (
Network string
Bind string
ReadTimeout int
WriteTimeout int
KeepAliveTimeout int
ClientKeepAliveTimeout int
DownloadTimeout int
Concurrency int
RequestsQueueSize int
MaxClients int
2021-04-26 13:52:50 +02:00
TTL int
CacheControlPassthrough bool
SetCanonicalHeader bool
SoReuseport bool
PathPrefix string
MaxSrcResolution int
MaxSrcFileSize int
MaxAnimationFrames int
MaxAnimationFrameResolution int
MaxSvgCheckBytes int
MaxRedirects int
2021-04-26 13:52:50 +02:00
JpegProgressive bool
PngInterlaced bool
PngQuantize bool
PngQuantizationColors int
AvifSpeed int
2021-04-26 13:52:50 +02:00
Quality int
FormatQuality map[imagetype.Type]int
StripMetadata bool
KeepCopyright bool
2021-04-26 13:52:50 +02:00
StripColorProfile bool
AutoRotate bool
EnforceThumbnail bool
ReturnAttachment bool
SvgFixUnsupported bool
2021-04-26 13:52:50 +02:00
EnableWebpDetection bool
EnforceWebp bool
EnableAvifDetection bool
EnforceAvif bool
EnableClientHints bool
2022-07-18 13:49:04 +02:00
PreferredFormats []imagetype.Type
2021-04-26 13:52:50 +02:00
SkipProcessingFormats []imagetype.Type
UseLinearColorspace bool
DisableShrinkOnLoad bool
Keys [][]byte
Salts [][]byte
SignatureSize int
Secret string
AllowOrigin string
UserAgent string
IgnoreSslVerification bool
DevelopmentErrorsMode bool
2021-11-11 11:30:16 +02:00
AllowedSources []*regexp.Regexp
2022-06-10 14:07:09 +02:00
SanitizeSvg bool
2021-11-11 11:30:16 +02:00
CookiePassthrough bool
CookieBaseURL string
2021-04-26 13:52:50 +02:00
LocalFileSystemRoot string
2022-04-06 13:35:44 +02:00
S3Enabled bool
S3Region string
S3Endpoint string
2022-04-07 19:31:50 +02:00
GCSEnabled bool
GCSKey string
GCSEndpoint string
2022-04-06 13:35:44 +02:00
ABSEnabled bool
ABSName string
ABSKey string
ABSEndpoint string
SwiftEnabled bool
SwiftUsername string
SwiftAPIKey string
SwiftAuthURL string
SwiftDomain string
SwiftTenant string
SwiftAuthVersion int
SwiftConnectTimeoutSeconds int
SwiftTimeoutSeconds int
2021-04-26 13:52:50 +02:00
ETagEnabled bool
2021-12-07 11:34:35 +02:00
ETagBuster string
2021-04-26 13:52:50 +02:00
2021-11-11 11:30:16 +02:00
BaseURL string
2021-04-26 13:52:50 +02:00
Presets []string
OnlyPresets bool
WatermarkData string
WatermarkPath string
WatermarkURL string
WatermarkOpacity float64
FallbackImageData string
FallbackImagePath string
FallbackImageURL string
FallbackImageHTTPCode int
FallbackImageTTL int
2021-04-26 13:52:50 +02:00
2022-07-07 10:17:27 +02:00
DataDogEnable bool
DataDogEnableMetrics bool
2021-04-26 13:52:50 +02:00
NewRelicAppName string
NewRelicKey string
2022-06-24 13:02:58 +02:00
NewRelicLabels map[string]string
2021-04-26 13:52:50 +02:00
PrometheusBind string
PrometheusNamespace string
2022-10-06 11:08:23 +02:00
OpenTelemetryEndpoint string
OpenTelemetryProtocol string
OpenTelemetryServiceName string
OpenTelemetryEnableMetrics bool
OpenTelemetryServerCert string
OpenTelemetryClientCert string
OpenTelemetryClientKey string
OpenTelemetryGRPCInsecure bool
2022-10-06 11:08:23 +02:00
OpenTelemetryPropagators []string
OpenTelemetryTraceIDGenerator string
2022-10-06 11:08:23 +02:00
OpenTelemetryConnectionTimeout int
2022-12-04 17:01:37 +02:00
CloudWatchServiceName string
CloudWatchNamespace string
CloudWatchRegion string
2021-04-26 13:52:50 +02:00
BugsnagKey string
BugsnagStage string
HoneybadgerKey string
HoneybadgerEnv string
SentryDSN string
SentryEnvironment string
SentryRelease string
AirbrakeProjecID int
AirbrakeProjecKey string
AirbrakeEnv string
2021-04-26 13:52:50 +02:00
ReportDownloadingErrors bool
EnableDebugHeaders bool
FreeMemoryInterval int
DownloadBufferSize int
BufferPoolCalibrationThreshold int
2022-02-21 14:06:20 +02:00
HealthCheckPath string
2021-04-26 13:52:50 +02:00
)
var (
2021-11-15 11:33:32 +02:00
keyPath string
saltPath string
presetsPath string
)
2021-04-26 13:52:50 +02:00
func init() {
Reset()
2021-11-15 11:33:32 +02:00
flag.StringVar(&keyPath, "keypath", "", "path of the file with hex-encoded key")
flag.StringVar(&saltPath, "saltpath", "", "path of the file with hex-encoded salt")
flag.StringVar(&presetsPath, "presets", "", "path of the file with presets")
2021-04-26 13:52:50 +02:00
}
func Reset() {
Network = "tcp"
Bind = ":8080"
ReadTimeout = 10
WriteTimeout = 10
KeepAliveTimeout = 10
ClientKeepAliveTimeout = 90
2021-04-26 13:52:50 +02:00
DownloadTimeout = 5
Concurrency = runtime.GOMAXPROCS(0) * 2
2022-07-20 15:46:21 +02:00
RequestsQueueSize = 0
MaxClients = 2048
2021-04-26 13:52:50 +02:00
2022-07-19 14:14:10 +02:00
TTL = 31536000
2021-04-26 13:52:50 +02:00
CacheControlPassthrough = false
SetCanonicalHeader = false
SoReuseport = false
PathPrefix = ""
MaxSrcResolution = 16800000
MaxSrcFileSize = 0
MaxAnimationFrames = 1
MaxAnimationFrameResolution = 0
2021-04-26 13:52:50 +02:00
MaxSvgCheckBytes = 32 * 1024
MaxRedirects = 10
2021-04-26 13:52:50 +02:00
JpegProgressive = false
PngInterlaced = false
PngQuantize = false
PngQuantizationColors = 256
AvifSpeed = 8
2021-04-26 13:52:50 +02:00
Quality = 80
FormatQuality = map[imagetype.Type]int{imagetype.AVIF: 65}
2021-04-26 13:52:50 +02:00
StripMetadata = true
KeepCopyright = true
2021-04-26 13:52:50 +02:00
StripColorProfile = true
AutoRotate = true
EnforceThumbnail = false
ReturnAttachment = false
SvgFixUnsupported = false
2021-04-26 13:52:50 +02:00
EnableWebpDetection = false
EnforceWebp = false
EnableAvifDetection = false
EnforceAvif = false
EnableClientHints = false
2022-07-18 13:49:04 +02:00
PreferredFormats = []imagetype.Type{
imagetype.JPEG,
imagetype.PNG,
imagetype.GIF,
}
2021-04-26 13:52:50 +02:00
SkipProcessingFormats = make([]imagetype.Type, 0)
UseLinearColorspace = false
DisableShrinkOnLoad = false
Keys = make([][]byte, 0)
Salts = make([][]byte, 0)
SignatureSize = 32
Secret = ""
AllowOrigin = ""
UserAgent = fmt.Sprintf("imgproxy/%s", version.Version())
IgnoreSslVerification = false
DevelopmentErrorsMode = false
2021-09-07 15:04:33 +02:00
AllowedSources = make([]*regexp.Regexp, 0)
2021-11-11 11:30:16 +02:00
2022-06-10 14:07:09 +02:00
SanitizeSvg = true
2021-11-11 11:30:16 +02:00
CookiePassthrough = false
CookieBaseURL = ""
2021-04-26 13:52:50 +02:00
LocalFileSystemRoot = ""
S3Enabled = false
S3Region = ""
S3Endpoint = ""
GCSEnabled = false
GCSKey = ""
ABSEnabled = false
ABSName = ""
ABSKey = ""
ABSEndpoint = ""
SwiftEnabled = false
SwiftUsername = ""
SwiftAPIKey = ""
SwiftAuthURL = ""
SwiftAuthVersion = 0
SwiftTenant = ""
SwiftDomain = ""
SwiftConnectTimeoutSeconds = 10
SwiftTimeoutSeconds = 60
2021-04-26 13:52:50 +02:00
ETagEnabled = false
2021-12-07 11:34:35 +02:00
ETagBuster = ""
2021-04-26 13:52:50 +02:00
BaseURL = ""
Presets = make([]string, 0)
OnlyPresets = false
WatermarkData = ""
WatermarkPath = ""
WatermarkURL = ""
WatermarkOpacity = 1
FallbackImageData = ""
FallbackImagePath = ""
FallbackImageURL = ""
FallbackImageHTTPCode = 200
FallbackImageTTL = 0
2021-04-26 13:52:50 +02:00
DataDogEnable = false
NewRelicAppName = ""
NewRelicKey = ""
2022-06-24 13:02:58 +02:00
NewRelicLabels = make(map[string]string)
2021-04-26 13:52:50 +02:00
PrometheusBind = ""
PrometheusNamespace = ""
2022-10-06 11:08:23 +02:00
OpenTelemetryEndpoint = ""
OpenTelemetryProtocol = "grpc"
OpenTelemetryServiceName = "imgproxy"
OpenTelemetryEnableMetrics = false
OpenTelemetryServerCert = ""
OpenTelemetryClientCert = ""
OpenTelemetryClientKey = ""
OpenTelemetryGRPCInsecure = true
2022-10-06 11:08:23 +02:00
OpenTelemetryPropagators = make([]string, 0)
OpenTelemetryTraceIDGenerator = "xray"
2022-10-06 11:08:23 +02:00
OpenTelemetryConnectionTimeout = 5
2022-12-04 17:01:37 +02:00
CloudWatchServiceName = ""
CloudWatchNamespace = "imgproxy"
CloudWatchRegion = ""
2021-04-26 13:52:50 +02:00
BugsnagKey = ""
BugsnagStage = "production"
HoneybadgerKey = ""
HoneybadgerEnv = "production"
SentryDSN = ""
SentryEnvironment = "production"
2021-11-23 11:11:39 +02:00
SentryRelease = fmt.Sprintf("imgproxy@%s", version.Version())
2021-04-26 13:52:50 +02:00
AirbrakeProjecID = 0
AirbrakeProjecKey = ""
AirbrakeEnv = "production"
2021-04-26 13:52:50 +02:00
ReportDownloadingErrors = true
EnableDebugHeaders = false
FreeMemoryInterval = 10
DownloadBufferSize = 0
BufferPoolCalibrationThreshold = 1024
2022-02-21 14:06:20 +02:00
HealthCheckPath = ""
2021-04-26 13:52:50 +02:00
}
func Configure() error {
if port := os.Getenv("PORT"); len(port) > 0 {
Bind = fmt.Sprintf(":%s", port)
}
configurators.String(&Network, "IMGPROXY_NETWORK")
configurators.String(&Bind, "IMGPROXY_BIND")
configurators.Int(&ReadTimeout, "IMGPROXY_READ_TIMEOUT")
configurators.Int(&WriteTimeout, "IMGPROXY_WRITE_TIMEOUT")
configurators.Int(&KeepAliveTimeout, "IMGPROXY_KEEP_ALIVE_TIMEOUT")
configurators.Int(&ClientKeepAliveTimeout, "IMGPROXY_CLIENT_KEEP_ALIVE_TIMEOUT")
2021-04-26 13:52:50 +02:00
configurators.Int(&DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT")
configurators.Int(&Concurrency, "IMGPROXY_CONCURRENCY")
2022-07-20 15:46:21 +02:00
configurators.Int(&RequestsQueueSize, "IMGPROXY_REQUESTS_QUEUE_SIZE")
2021-04-26 13:52:50 +02:00
configurators.Int(&MaxClients, "IMGPROXY_MAX_CLIENTS")
configurators.Int(&TTL, "IMGPROXY_TTL")
configurators.Bool(&CacheControlPassthrough, "IMGPROXY_CACHE_CONTROL_PASSTHROUGH")
configurators.Bool(&SetCanonicalHeader, "IMGPROXY_SET_CANONICAL_HEADER")
configurators.Bool(&SoReuseport, "IMGPROXY_SO_REUSEPORT")
configurators.String(&PathPrefix, "IMGPROXY_PATH_PREFIX")
configurators.MegaInt(&MaxSrcResolution, "IMGPROXY_MAX_SRC_RESOLUTION")
configurators.Int(&MaxSrcFileSize, "IMGPROXY_MAX_SRC_FILE_SIZE")
configurators.Int(&MaxSvgCheckBytes, "IMGPROXY_MAX_SVG_CHECK_BYTES")
configurators.Int(&MaxAnimationFrames, "IMGPROXY_MAX_ANIMATION_FRAMES")
configurators.MegaInt(&MaxAnimationFrameResolution, "IMGPROXY_MAX_ANIMATION_FRAME_RESOLUTION")
2021-04-26 13:52:50 +02:00
configurators.Int(&MaxRedirects, "IMGPROXY_MAX_REDIRECTS")
2021-09-07 15:04:33 +02:00
configurators.Patterns(&AllowedSources, "IMGPROXY_ALLOWED_SOURCES")
2021-04-26 13:52:50 +02:00
2022-06-10 14:07:09 +02:00
configurators.Bool(&SanitizeSvg, "IMGPROXY_SANITIZE_SVG")
2021-04-26 13:52:50 +02:00
configurators.Bool(&JpegProgressive, "IMGPROXY_JPEG_PROGRESSIVE")
configurators.Bool(&PngInterlaced, "IMGPROXY_PNG_INTERLACED")
configurators.Bool(&PngQuantize, "IMGPROXY_PNG_QUANTIZE")
configurators.Int(&PngQuantizationColors, "IMGPROXY_PNG_QUANTIZATION_COLORS")
configurators.Int(&AvifSpeed, "IMGPROXY_AVIF_SPEED")
2021-04-26 13:52:50 +02:00
configurators.Int(&Quality, "IMGPROXY_QUALITY")
if err := configurators.ImageTypesQuality(FormatQuality, "IMGPROXY_FORMAT_QUALITY"); err != nil {
return err
}
configurators.Bool(&StripMetadata, "IMGPROXY_STRIP_METADATA")
configurators.Bool(&KeepCopyright, "IMGPROXY_KEEP_COPYRIGHT")
2021-04-26 13:52:50 +02:00
configurators.Bool(&StripColorProfile, "IMGPROXY_STRIP_COLOR_PROFILE")
configurators.Bool(&AutoRotate, "IMGPROXY_AUTO_ROTATE")
configurators.Bool(&EnforceThumbnail, "IMGPROXY_ENFORCE_THUMBNAIL")
configurators.Bool(&ReturnAttachment, "IMGPROXY_RETURN_ATTACHMENT")
configurators.Bool(&SvgFixUnsupported, "IMGPROXY_SVG_FIX_UNSUPPORTED")
2021-04-26 13:52:50 +02:00
configurators.Bool(&EnableWebpDetection, "IMGPROXY_ENABLE_WEBP_DETECTION")
configurators.Bool(&EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
configurators.Bool(&EnableAvifDetection, "IMGPROXY_ENABLE_AVIF_DETECTION")
configurators.Bool(&EnforceAvif, "IMGPROXY_ENFORCE_AVIF")
configurators.Bool(&EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
2022-02-21 14:06:20 +02:00
configurators.String(&HealthCheckPath, "IMGPROXY_HEALTH_CHECK_PATH")
2022-07-18 13:49:04 +02:00
if err := configurators.ImageTypes(&PreferredFormats, "IMGPROXY_PREFERRED_FORMATS"); err != nil {
return err
}
2021-04-26 13:52:50 +02:00
if err := configurators.ImageTypes(&SkipProcessingFormats, "IMGPROXY_SKIP_PROCESSING_FORMATS"); err != nil {
return err
}
configurators.Bool(&UseLinearColorspace, "IMGPROXY_USE_LINEAR_COLORSPACE")
configurators.Bool(&DisableShrinkOnLoad, "IMGPROXY_DISABLE_SHRINK_ON_LOAD")
if err := configurators.HexSlice(&Keys, "IMGPROXY_KEY"); err != nil {
2021-04-26 13:52:50 +02:00
return err
}
if err := configurators.HexSlice(&Salts, "IMGPROXY_SALT"); err != nil {
2021-04-26 13:52:50 +02:00
return err
}
configurators.Int(&SignatureSize, "IMGPROXY_SIGNATURE_SIZE")
if err := configurators.HexSliceFile(&Keys, keyPath); err != nil {
2021-04-26 13:52:50 +02:00
return err
}
if err := configurators.HexSliceFile(&Salts, saltPath); err != nil {
2021-04-26 13:52:50 +02:00
return err
}
configurators.String(&Secret, "IMGPROXY_SECRET")
configurators.String(&AllowOrigin, "IMGPROXY_ALLOW_ORIGIN")
configurators.String(&UserAgent, "IMGPROXY_USER_AGENT")
configurators.Bool(&IgnoreSslVerification, "IMGPROXY_IGNORE_SSL_VERIFICATION")
configurators.Bool(&DevelopmentErrorsMode, "IMGPROXY_DEVELOPMENT_ERRORS_MODE")
2021-11-11 11:30:16 +02:00
configurators.Bool(&CookiePassthrough, "IMGPROXY_COOKIE_PASSTHROUGH")
configurators.String(&CookieBaseURL, "IMGPROXY_COOKIE_BASE_URL")
2021-04-26 13:52:50 +02:00
configurators.String(&LocalFileSystemRoot, "IMGPROXY_LOCAL_FILESYSTEM_ROOT")
configurators.Bool(&S3Enabled, "IMGPROXY_USE_S3")
configurators.String(&S3Region, "IMGPROXY_S3_REGION")
configurators.String(&S3Endpoint, "IMGPROXY_S3_ENDPOINT")
configurators.Bool(&GCSEnabled, "IMGPROXY_USE_GCS")
configurators.String(&GCSKey, "IMGPROXY_GCS_KEY")
2022-04-07 19:31:50 +02:00
configurators.String(&GCSEndpoint, "IMGPROXY_GCS_ENDPOINT")
2021-04-26 13:52:50 +02:00
configurators.Bool(&ABSEnabled, "IMGPROXY_USE_ABS")
configurators.String(&ABSName, "IMGPROXY_ABS_NAME")
configurators.String(&ABSKey, "IMGPROXY_ABS_KEY")
configurators.String(&ABSEndpoint, "IMGPROXY_ABS_ENDPOINT")
configurators.Bool(&SwiftEnabled, "IMGPROXY_USE_SWIFT")
configurators.String(&SwiftUsername, "IMGPROXY_SWIFT_USERNAME")
configurators.String(&SwiftAPIKey, "IMGPROXY_SWIFT_API_KEY")
configurators.String(&SwiftAuthURL, "IMGPROXY_SWIFT_AUTH_URL")
configurators.String(&SwiftDomain, "IMGPROXY_SWIFT_DOMAIN")
configurators.String(&SwiftTenant, "IMGPROXY_SWIFT_TENANT")
configurators.Int(&SwiftConnectTimeoutSeconds, "IMGPROXY_SWIFT_CONNECT_TIMEOUT_SECONDS")
configurators.Int(&SwiftTimeoutSeconds, "IMGPROXY_SWIFT_TIMEOUT_SECONDS")
2021-04-26 13:52:50 +02:00
configurators.Bool(&ETagEnabled, "IMGPROXY_USE_ETAG")
2021-12-07 11:34:35 +02:00
configurators.String(&ETagBuster, "IMGPROXY_ETAG_BUSTER")
2021-04-26 13:52:50 +02:00
configurators.String(&BaseURL, "IMGPROXY_BASE_URL")
configurators.StringSlice(&Presets, "IMGPROXY_PRESETS")
2021-11-15 11:33:32 +02:00
if err := configurators.StringSliceFile(&Presets, presetsPath); err != nil {
2021-04-26 13:52:50 +02:00
return err
}
configurators.Bool(&OnlyPresets, "IMGPROXY_ONLY_PRESETS")
configurators.String(&WatermarkData, "IMGPROXY_WATERMARK_DATA")
configurators.String(&WatermarkPath, "IMGPROXY_WATERMARK_PATH")
configurators.String(&WatermarkURL, "IMGPROXY_WATERMARK_URL")
configurators.Float(&WatermarkOpacity, "IMGPROXY_WATERMARK_OPACITY")
configurators.String(&FallbackImageData, "IMGPROXY_FALLBACK_IMAGE_DATA")
configurators.String(&FallbackImagePath, "IMGPROXY_FALLBACK_IMAGE_PATH")
configurators.String(&FallbackImageURL, "IMGPROXY_FALLBACK_IMAGE_URL")
configurators.Int(&FallbackImageHTTPCode, "IMGPROXY_FALLBACK_IMAGE_HTTP_CODE")
configurators.Int(&FallbackImageTTL, "IMGPROXY_FALLBACK_IMAGE_TTL")
2021-04-26 13:52:50 +02:00
configurators.Bool(&DataDogEnable, "IMGPROXY_DATADOG_ENABLE")
2022-07-07 10:17:27 +02:00
configurators.Bool(&DataDogEnableMetrics, "IMGPROXY_DATADOG_ENABLE_ADDITIONAL_METRICS")
2021-04-26 13:52:50 +02:00
configurators.String(&NewRelicAppName, "IMGPROXY_NEW_RELIC_APP_NAME")
configurators.String(&NewRelicKey, "IMGPROXY_NEW_RELIC_KEY")
2022-06-24 13:02:58 +02:00
configurators.StringMap(&NewRelicLabels, "IMGPROXY_NEW_RELIC_LABELS")
2021-04-26 13:52:50 +02:00
configurators.String(&PrometheusBind, "IMGPROXY_PROMETHEUS_BIND")
configurators.String(&PrometheusNamespace, "IMGPROXY_PROMETHEUS_NAMESPACE")
2022-10-06 11:08:23 +02:00
configurators.String(&OpenTelemetryEndpoint, "IMGPROXY_OPEN_TELEMETRY_ENDPOINT")
configurators.String(&OpenTelemetryProtocol, "IMGPROXY_OPEN_TELEMETRY_PROTOCOL")
configurators.String(&OpenTelemetryServiceName, "IMGPROXY_OPEN_TELEMETRY_SERVICE_NAME")
configurators.Bool(&OpenTelemetryEnableMetrics, "IMGPROXY_OPEN_TELEMETRY_ENABLE_METRICS")
configurators.String(&OpenTelemetryServerCert, "IMGPROXY_OPEN_TELEMETRY_SERVER_CERT")
configurators.String(&OpenTelemetryClientCert, "IMGPROXY_OPEN_TELEMETRY_CLIENT_CERT")
configurators.String(&OpenTelemetryClientKey, "IMGPROXY_OPEN_TELEMETRY_CLIENT_KEY")
configurators.Bool(&OpenTelemetryGRPCInsecure, "IMGPROXY_OPEN_TELEMETRY_GRPC_INSECURE")
2022-10-06 11:08:23 +02:00
configurators.StringSlice(&OpenTelemetryPropagators, "IMGPROXY_OPEN_TELEMETRY_PROPAGATORS")
configurators.String(&OpenTelemetryTraceIDGenerator, "IMGPROXY_OPEN_TELEMETRY_TRACE_ID_GENERATOR")
2022-10-06 11:08:23 +02:00
configurators.Int(&OpenTelemetryConnectionTimeout, "IMGPROXY_OPEN_TELEMETRY_CONNECTION_TIMEOUT")
2022-12-04 17:01:37 +02:00
configurators.String(&CloudWatchServiceName, "IMGPROXY_CLOUD_WATCH_SERVICE_NAME")
configurators.String(&CloudWatchNamespace, "IMGPROXY_CLOUD_WATCH_NAMESPACE")
configurators.String(&CloudWatchRegion, "IMGPROXY_CLOUD_WATCH_REGION")
2021-04-26 13:52:50 +02:00
configurators.String(&BugsnagKey, "IMGPROXY_BUGSNAG_KEY")
configurators.String(&BugsnagStage, "IMGPROXY_BUGSNAG_STAGE")
configurators.String(&HoneybadgerKey, "IMGPROXY_HONEYBADGER_KEY")
configurators.String(&HoneybadgerEnv, "IMGPROXY_HONEYBADGER_ENV")
configurators.String(&SentryDSN, "IMGPROXY_SENTRY_DSN")
configurators.String(&SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT")
configurators.String(&SentryRelease, "IMGPROXY_SENTRY_RELEASE")
configurators.Int(&AirbrakeProjecID, "IMGPROXY_AIRBRAKE_PROJECT_ID")
configurators.String(&AirbrakeProjecKey, "IMGPROXY_AIRBRAKE_PROJECT_KEY")
configurators.String(&AirbrakeEnv, "IMGPROXY_AIRBRAKE_ENVIRONMENT")
2021-04-26 13:52:50 +02:00
configurators.Bool(&ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS")
configurators.Bool(&EnableDebugHeaders, "IMGPROXY_ENABLE_DEBUG_HEADERS")
configurators.Int(&FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL")
configurators.Int(&DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE")
configurators.Int(&BufferPoolCalibrationThreshold, "IMGPROXY_BUFFER_POOL_CALIBRATION_THRESHOLD")
if len(Keys) != len(Salts) {
return fmt.Errorf("Number of keys and number of salts should be equal. Keys: %d, salts: %d", len(Keys), len(Salts))
}
if len(Keys) == 0 {
log.Warning("No keys defined, so signature checking is disabled")
}
if len(Salts) == 0 {
log.Warning("No salts defined, so signature checking is disabled")
}
if SignatureSize < 1 || SignatureSize > 32 {
return fmt.Errorf("Signature size should be within 1 and 32, now - %d\n", SignatureSize)
}
if len(Bind) == 0 {
return errors.New("Bind address is not defined")
2021-04-26 13:52:50 +02:00
}
if ReadTimeout <= 0 {
return fmt.Errorf("Read timeout should be greater than 0, now - %d\n", ReadTimeout)
}
if WriteTimeout <= 0 {
return fmt.Errorf("Write timeout should be greater than 0, now - %d\n", WriteTimeout)
}
if KeepAliveTimeout < 0 {
return fmt.Errorf("KeepAlive timeout should be greater than or equal to 0, now - %d\n", KeepAliveTimeout)
}
if ClientKeepAliveTimeout < 0 {
return fmt.Errorf("Client KeepAlive timeout should be greater than or equal to 0, now - %d\n", ClientKeepAliveTimeout)
}
2021-04-26 13:52:50 +02:00
if DownloadTimeout <= 0 {
return fmt.Errorf("Download timeout should be greater than 0, now - %d\n", DownloadTimeout)
}
if Concurrency <= 0 {
return fmt.Errorf("Concurrency should be greater than 0, now - %d\n", Concurrency)
}
2022-07-20 15:46:21 +02:00
if RequestsQueueSize < 0 {
return fmt.Errorf("Requests queue size should be greater than or equal 0, now - %d\n", RequestsQueueSize)
}
if MaxClients < 0 {
return fmt.Errorf("Concurrency should be greater than or equal 0, now - %d\n", MaxClients)
2021-04-26 13:52:50 +02:00
}
if TTL <= 0 {
return fmt.Errorf("TTL should be greater than 0, now - %d\n", TTL)
}
if MaxSrcResolution <= 0 {
return fmt.Errorf("Max src resolution should be greater than 0, now - %d\n", MaxSrcResolution)
}
if MaxSrcFileSize < 0 {
return fmt.Errorf("Max src file size should be greater than or equal to 0, now - %d\n", MaxSrcFileSize)
}
if MaxAnimationFrames <= 0 {
return fmt.Errorf("Max animation frames should be greater than 0, now - %d\n", MaxAnimationFrames)
}
if PngQuantizationColors < 2 {
return fmt.Errorf("Png quantization colors should be greater than 1, now - %d\n", PngQuantizationColors)
} else if PngQuantizationColors > 256 {
return fmt.Errorf("Png quantization colors can't be greater than 256, now - %d\n", PngQuantizationColors)
}
if AvifSpeed < 0 {
return fmt.Errorf("Avif speed should be greater than 0, now - %d\n", AvifSpeed)
} else if AvifSpeed > 8 {
return fmt.Errorf("Avif speed can't be greater than 8, now - %d\n", AvifSpeed)
}
2021-04-26 13:52:50 +02:00
if Quality <= 0 {
return fmt.Errorf("Quality should be greater than 0, now - %d\n", Quality)
} else if Quality > 100 {
return fmt.Errorf("Quality can't be greater than 100, now - %d\n", Quality)
}
2022-07-18 13:49:04 +02:00
if len(PreferredFormats) == 0 {
return errors.New("At least one preferred format should be specified")
2022-07-18 13:49:04 +02:00
}
2021-04-26 13:52:50 +02:00
if IgnoreSslVerification {
log.Warning("Ignoring SSL verification is very unsafe")
}
if LocalFileSystemRoot != "" {
stat, err := os.Stat(LocalFileSystemRoot)
if err != nil {
return fmt.Errorf("Cannot use local directory: %s", err)
}
if !stat.IsDir() {
return errors.New("Cannot use local directory: not a directory")
2021-04-26 13:52:50 +02:00
}
if LocalFileSystemRoot == "/" {
log.Warning("Exposing root via IMGPROXY_LOCAL_FILESYSTEM_ROOT is unsafe")
}
}
if _, ok := os.LookupEnv("IMGPROXY_USE_GCS"); !ok && len(GCSKey) > 0 {
log.Warning("Set IMGPROXY_USE_GCS to true since it may be required by future versions to enable GCS support")
GCSEnabled = true
}
if WatermarkOpacity <= 0 {
return errors.New("Watermark opacity should be greater than 0")
2021-04-26 13:52:50 +02:00
} else if WatermarkOpacity > 1 {
return errors.New("Watermark opacity should be less than or equal to 1")
2021-04-26 13:52:50 +02:00
}
if FallbackImageHTTPCode < 100 || FallbackImageHTTPCode > 599 {
return errors.New("Fallback image HTTP code should be between 100 and 599")
2021-04-26 13:52:50 +02:00
}
if len(PrometheusBind) > 0 && PrometheusBind == Bind {
return errors.New("Can't use the same binding for the main server and Prometheus")
2021-04-26 13:52:50 +02:00
}
2022-10-06 11:08:23 +02:00
if OpenTelemetryConnectionTimeout < 1 {
return errors.New("OpenTelemetry connection timeout should be greater than zero")
2022-10-06 11:08:23 +02:00
}
2021-04-26 13:52:50 +02:00
if FreeMemoryInterval <= 0 {
return errors.New("Free memory interval should be greater than zero")
2021-04-26 13:52:50 +02:00
}
if DownloadBufferSize < 0 {
return errors.New("Download buffer size should be greater than or equal to 0")
2021-04-26 13:52:50 +02:00
} else if DownloadBufferSize > math.MaxInt32 {
return fmt.Errorf("Download buffer size can't be greater than %d", math.MaxInt32)
}
if BufferPoolCalibrationThreshold < 64 {
return errors.New("Buffer pool calibration threshold should be greater than or equal to 64")
2021-04-26 13:52:50 +02:00
}
return nil
}