config.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. package main
  2. import (
  3. "bufio"
  4. "encoding/hex"
  5. "flag"
  6. "fmt"
  7. "math"
  8. "os"
  9. "runtime"
  10. "strconv"
  11. "strings"
  12. )
  13. func intEnvConfig(i *int, name string) {
  14. if env, err := strconv.Atoi(os.Getenv(name)); err == nil {
  15. *i = env
  16. }
  17. }
  18. func floatEnvConfig(i *float64, name string) {
  19. if env, err := strconv.ParseFloat(os.Getenv(name), 64); err == nil {
  20. *i = env
  21. }
  22. }
  23. func megaIntEnvConfig(f *int, name string) {
  24. if env, err := strconv.ParseFloat(os.Getenv(name), 64); err == nil {
  25. *f = int(env * 1000000)
  26. }
  27. }
  28. func strEnvConfig(s *string, name string) {
  29. if env := os.Getenv(name); len(env) > 0 {
  30. *s = env
  31. }
  32. }
  33. func strSliceEnvConfig(s *[]string, name string) {
  34. if env := os.Getenv(name); len(env) > 0 {
  35. parts := strings.Split(env, ",")
  36. for i, p := range parts {
  37. parts[i] = strings.TrimSpace(p)
  38. }
  39. *s = parts
  40. return
  41. }
  42. *s = []string{}
  43. }
  44. func boolEnvConfig(b *bool, name string) {
  45. if env, err := strconv.ParseBool(os.Getenv(name)); err == nil {
  46. *b = env
  47. }
  48. }
  49. func imageTypesEnvConfig(it *[]imageType, name string) {
  50. *it = []imageType{}
  51. if env := os.Getenv(name); len(env) > 0 {
  52. parts := strings.Split(env, ",")
  53. for _, p := range parts {
  54. pt := strings.TrimSpace(p)
  55. if t, ok := imageTypes[pt]; ok {
  56. *it = append(*it, t)
  57. } else {
  58. logWarning("Unknown image format to skip: %s", pt)
  59. }
  60. }
  61. }
  62. }
  63. func formatQualityEnvConfig(m map[imageType]int, name string) {
  64. if env := os.Getenv(name); len(env) > 0 {
  65. parts := strings.Split(env, ",")
  66. for _, p := range parts {
  67. i := strings.Index(p, "=")
  68. if i < 0 {
  69. logWarning("Invalid format quality string: %s", p)
  70. continue
  71. }
  72. imgtypeStr, qStr := strings.TrimSpace(p[:i]), strings.TrimSpace(p[i+1:])
  73. imgtype, ok := imageTypes[imgtypeStr]
  74. if !ok {
  75. logWarning("Invalid format: %s", p)
  76. }
  77. q, err := strconv.Atoi(qStr)
  78. if err != nil || q <= 0 || q > 100 {
  79. logWarning("Invalid quality: %s", p)
  80. }
  81. m[imgtype] = q
  82. }
  83. }
  84. }
  85. func hexEnvConfig(b *[]securityKey, name string) error {
  86. var err error
  87. if env := os.Getenv(name); len(env) > 0 {
  88. parts := strings.Split(env, ",")
  89. keys := make([]securityKey, len(parts))
  90. for i, part := range parts {
  91. if keys[i], err = hex.DecodeString(part); err != nil {
  92. return fmt.Errorf("%s expected to be hex-encoded strings. Invalid: %s\n", name, part)
  93. }
  94. }
  95. *b = keys
  96. }
  97. return nil
  98. }
  99. func hexFileConfig(b *[]securityKey, filepath string) error {
  100. if len(filepath) == 0 {
  101. return nil
  102. }
  103. f, err := os.Open(filepath)
  104. if err != nil {
  105. return fmt.Errorf("Can't open file %s\n", filepath)
  106. }
  107. keys := []securityKey{}
  108. scanner := bufio.NewScanner(f)
  109. for scanner.Scan() {
  110. part := scanner.Text()
  111. if len(part) == 0 {
  112. continue
  113. }
  114. if key, err := hex.DecodeString(part); err == nil {
  115. keys = append(keys, key)
  116. } else {
  117. return fmt.Errorf("%s expected to contain hex-encoded strings. Invalid: %s\n", filepath, part)
  118. }
  119. }
  120. if err := scanner.Err(); err != nil {
  121. return fmt.Errorf("Failed to read file %s: %s", filepath, err)
  122. }
  123. *b = keys
  124. return nil
  125. }
  126. func presetEnvConfig(p presets, name string) error {
  127. if env := os.Getenv(name); len(env) > 0 {
  128. presetStrings := strings.Split(env, ",")
  129. for _, presetStr := range presetStrings {
  130. if err := parsePreset(p, presetStr); err != nil {
  131. return fmt.Errorf(err.Error())
  132. }
  133. }
  134. }
  135. return nil
  136. }
  137. func presetFileConfig(p presets, filepath string) error {
  138. if len(filepath) == 0 {
  139. return nil
  140. }
  141. f, err := os.Open(filepath)
  142. if err != nil {
  143. return fmt.Errorf("Can't open file %s\n", filepath)
  144. }
  145. scanner := bufio.NewScanner(f)
  146. for scanner.Scan() {
  147. if err := parsePreset(p, scanner.Text()); err != nil {
  148. return fmt.Errorf(err.Error())
  149. }
  150. }
  151. if err := scanner.Err(); err != nil {
  152. return fmt.Errorf("Failed to read presets file: %s", err)
  153. }
  154. return nil
  155. }
  156. type config struct {
  157. Network string
  158. Bind string
  159. ReadTimeout int
  160. WriteTimeout int
  161. KeepAliveTimeout int
  162. DownloadTimeout int
  163. Concurrency int
  164. MaxClients int
  165. TTL int
  166. CacheControlPassthrough bool
  167. SetCanonicalHeader bool
  168. SoReuseport bool
  169. PathPrefix string
  170. MaxSrcResolution int
  171. MaxSrcFileSize int
  172. MaxAnimationFrames int
  173. MaxSvgCheckBytes int
  174. JpegProgressive bool
  175. PngInterlaced bool
  176. PngQuantize bool
  177. PngQuantizationColors int
  178. Quality int
  179. FormatQuality map[imageType]int
  180. StripMetadata bool
  181. StripColorProfile bool
  182. AutoRotate bool
  183. EnableWebpDetection bool
  184. EnforceWebp bool
  185. EnableAvifDetection bool
  186. EnforceAvif bool
  187. EnableClientHints bool
  188. SkipProcessingFormats []imageType
  189. UseLinearColorspace bool
  190. DisableShrinkOnLoad bool
  191. Keys []securityKey
  192. Salts []securityKey
  193. AllowInsecure bool
  194. SignatureSize int
  195. Secret string
  196. AllowOrigin string
  197. UserAgent string
  198. IgnoreSslVerification bool
  199. DevelopmentErrorsMode bool
  200. AllowedSources []string
  201. LocalFileSystemRoot string
  202. S3Enabled bool
  203. S3Region string
  204. S3Endpoint string
  205. GCSEnabled bool
  206. GCSKey string
  207. ABSEnabled bool
  208. ABSName string
  209. ABSKey string
  210. ABSEndpoint string
  211. ETagEnabled bool
  212. BaseURL string
  213. Presets presets
  214. OnlyPresets bool
  215. WatermarkData string
  216. WatermarkPath string
  217. WatermarkURL string
  218. WatermarkOpacity float64
  219. FallbackImageData string
  220. FallbackImagePath string
  221. FallbackImageURL string
  222. FallbackImageHTTPCode int
  223. NewRelicAppName string
  224. NewRelicKey string
  225. PrometheusBind string
  226. PrometheusNamespace string
  227. BugsnagKey string
  228. BugsnagStage string
  229. HoneybadgerKey string
  230. HoneybadgerEnv string
  231. SentryDSN string
  232. SentryEnvironment string
  233. SentryRelease string
  234. ReportDownloadingErrors bool
  235. EnableDebugHeaders bool
  236. FreeMemoryInterval int
  237. DownloadBufferSize int
  238. BufferPoolCalibrationThreshold int
  239. }
  240. var conf = config{
  241. Network: "tcp",
  242. Bind: ":8080",
  243. ReadTimeout: 10,
  244. WriteTimeout: 10,
  245. KeepAliveTimeout: 10,
  246. DownloadTimeout: 5,
  247. Concurrency: runtime.NumCPU() * 2,
  248. TTL: 3600,
  249. MaxSrcResolution: 16800000,
  250. MaxAnimationFrames: 1,
  251. MaxSvgCheckBytes: 32 * 1024,
  252. SignatureSize: 32,
  253. PngQuantizationColors: 256,
  254. Quality: 80,
  255. FormatQuality: map[imageType]int{imageTypeAVIF: 50},
  256. StripMetadata: true,
  257. StripColorProfile: true,
  258. AutoRotate: true,
  259. UserAgent: fmt.Sprintf("imgproxy/%s", version),
  260. Presets: make(presets),
  261. WatermarkOpacity: 1,
  262. FallbackImageHTTPCode: 200,
  263. BugsnagStage: "production",
  264. HoneybadgerEnv: "production",
  265. SentryEnvironment: "production",
  266. SentryRelease: fmt.Sprintf("imgproxy/%s", version),
  267. ReportDownloadingErrors: true,
  268. FreeMemoryInterval: 10,
  269. BufferPoolCalibrationThreshold: 1024,
  270. }
  271. func configure() error {
  272. keyPath := flag.String("keypath", "", "path of the file with hex-encoded key")
  273. saltPath := flag.String("saltpath", "", "path of the file with hex-encoded salt")
  274. presetsPath := flag.String("presets", "", "path of the file with presets")
  275. flag.Parse()
  276. if port := os.Getenv("PORT"); len(port) > 0 {
  277. conf.Bind = fmt.Sprintf(":%s", port)
  278. }
  279. strEnvConfig(&conf.Network, "IMGPROXY_NETWORK")
  280. strEnvConfig(&conf.Bind, "IMGPROXY_BIND")
  281. intEnvConfig(&conf.ReadTimeout, "IMGPROXY_READ_TIMEOUT")
  282. intEnvConfig(&conf.WriteTimeout, "IMGPROXY_WRITE_TIMEOUT")
  283. intEnvConfig(&conf.KeepAliveTimeout, "IMGPROXY_KEEP_ALIVE_TIMEOUT")
  284. intEnvConfig(&conf.DownloadTimeout, "IMGPROXY_DOWNLOAD_TIMEOUT")
  285. intEnvConfig(&conf.Concurrency, "IMGPROXY_CONCURRENCY")
  286. intEnvConfig(&conf.MaxClients, "IMGPROXY_MAX_CLIENTS")
  287. intEnvConfig(&conf.TTL, "IMGPROXY_TTL")
  288. boolEnvConfig(&conf.CacheControlPassthrough, "IMGPROXY_CACHE_CONTROL_PASSTHROUGH")
  289. boolEnvConfig(&conf.SetCanonicalHeader, "IMGPROXY_SET_CANONICAL_HEADER")
  290. boolEnvConfig(&conf.SoReuseport, "IMGPROXY_SO_REUSEPORT")
  291. strEnvConfig(&conf.PathPrefix, "IMGPROXY_PATH_PREFIX")
  292. megaIntEnvConfig(&conf.MaxSrcResolution, "IMGPROXY_MAX_SRC_RESOLUTION")
  293. intEnvConfig(&conf.MaxSrcFileSize, "IMGPROXY_MAX_SRC_FILE_SIZE")
  294. intEnvConfig(&conf.MaxSvgCheckBytes, "IMGPROXY_MAX_SVG_CHECK_BYTES")
  295. intEnvConfig(&conf.MaxAnimationFrames, "IMGPROXY_MAX_ANIMATION_FRAMES")
  296. strSliceEnvConfig(&conf.AllowedSources, "IMGPROXY_ALLOWED_SOURCES")
  297. boolEnvConfig(&conf.JpegProgressive, "IMGPROXY_JPEG_PROGRESSIVE")
  298. boolEnvConfig(&conf.PngInterlaced, "IMGPROXY_PNG_INTERLACED")
  299. boolEnvConfig(&conf.PngQuantize, "IMGPROXY_PNG_QUANTIZE")
  300. intEnvConfig(&conf.PngQuantizationColors, "IMGPROXY_PNG_QUANTIZATION_COLORS")
  301. intEnvConfig(&conf.Quality, "IMGPROXY_QUALITY")
  302. formatQualityEnvConfig(conf.FormatQuality, "IMGPROXY_FORMAT_QUALITY")
  303. boolEnvConfig(&conf.StripMetadata, "IMGPROXY_STRIP_METADATA")
  304. boolEnvConfig(&conf.StripColorProfile, "IMGPROXY_STRIP_COLOR_PROFILE")
  305. boolEnvConfig(&conf.AutoRotate, "IMGPROXY_AUTO_ROTATE")
  306. boolEnvConfig(&conf.EnableWebpDetection, "IMGPROXY_ENABLE_WEBP_DETECTION")
  307. boolEnvConfig(&conf.EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
  308. boolEnvConfig(&conf.EnableAvifDetection, "IMGPROXY_ENABLE_AVIF_DETECTION")
  309. boolEnvConfig(&conf.EnforceAvif, "IMGPROXY_ENFORCE_AVIF")
  310. boolEnvConfig(&conf.EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
  311. imageTypesEnvConfig(&conf.SkipProcessingFormats, "IMGPROXY_SKIP_PROCESSING_FORMATS")
  312. boolEnvConfig(&conf.UseLinearColorspace, "IMGPROXY_USE_LINEAR_COLORSPACE")
  313. boolEnvConfig(&conf.DisableShrinkOnLoad, "IMGPROXY_DISABLE_SHRINK_ON_LOAD")
  314. if err := hexEnvConfig(&conf.Keys, "IMGPROXY_KEY"); err != nil {
  315. return err
  316. }
  317. if err := hexEnvConfig(&conf.Salts, "IMGPROXY_SALT"); err != nil {
  318. return err
  319. }
  320. intEnvConfig(&conf.SignatureSize, "IMGPROXY_SIGNATURE_SIZE")
  321. if err := hexFileConfig(&conf.Keys, *keyPath); err != nil {
  322. return err
  323. }
  324. if err := hexFileConfig(&conf.Salts, *saltPath); err != nil {
  325. return err
  326. }
  327. strEnvConfig(&conf.Secret, "IMGPROXY_SECRET")
  328. strEnvConfig(&conf.AllowOrigin, "IMGPROXY_ALLOW_ORIGIN")
  329. strEnvConfig(&conf.UserAgent, "IMGPROXY_USER_AGENT")
  330. boolEnvConfig(&conf.IgnoreSslVerification, "IMGPROXY_IGNORE_SSL_VERIFICATION")
  331. boolEnvConfig(&conf.DevelopmentErrorsMode, "IMGPROXY_DEVELOPMENT_ERRORS_MODE")
  332. strEnvConfig(&conf.LocalFileSystemRoot, "IMGPROXY_LOCAL_FILESYSTEM_ROOT")
  333. boolEnvConfig(&conf.S3Enabled, "IMGPROXY_USE_S3")
  334. strEnvConfig(&conf.S3Region, "IMGPROXY_S3_REGION")
  335. strEnvConfig(&conf.S3Endpoint, "IMGPROXY_S3_ENDPOINT")
  336. boolEnvConfig(&conf.GCSEnabled, "IMGPROXY_USE_GCS")
  337. strEnvConfig(&conf.GCSKey, "IMGPROXY_GCS_KEY")
  338. boolEnvConfig(&conf.ABSEnabled, "IMGPROXY_USE_ABS")
  339. strEnvConfig(&conf.ABSName, "IMGPROXY_ABS_NAME")
  340. strEnvConfig(&conf.ABSKey, "IMGPROXY_ABS_KEY")
  341. strEnvConfig(&conf.ABSEndpoint, "IMGPROXY_ABS_ENDPOINT")
  342. boolEnvConfig(&conf.ETagEnabled, "IMGPROXY_USE_ETAG")
  343. strEnvConfig(&conf.BaseURL, "IMGPROXY_BASE_URL")
  344. if err := presetEnvConfig(conf.Presets, "IMGPROXY_PRESETS"); err != nil {
  345. return err
  346. }
  347. if err := presetFileConfig(conf.Presets, *presetsPath); err != nil {
  348. return err
  349. }
  350. boolEnvConfig(&conf.OnlyPresets, "IMGPROXY_ONLY_PRESETS")
  351. strEnvConfig(&conf.WatermarkData, "IMGPROXY_WATERMARK_DATA")
  352. strEnvConfig(&conf.WatermarkPath, "IMGPROXY_WATERMARK_PATH")
  353. strEnvConfig(&conf.WatermarkURL, "IMGPROXY_WATERMARK_URL")
  354. floatEnvConfig(&conf.WatermarkOpacity, "IMGPROXY_WATERMARK_OPACITY")
  355. strEnvConfig(&conf.FallbackImageData, "IMGPROXY_FALLBACK_IMAGE_DATA")
  356. strEnvConfig(&conf.FallbackImagePath, "IMGPROXY_FALLBACK_IMAGE_PATH")
  357. strEnvConfig(&conf.FallbackImageURL, "IMGPROXY_FALLBACK_IMAGE_URL")
  358. intEnvConfig(&conf.FallbackImageHTTPCode, "IMGPROXY_FALLBACK_IMAGE_HTTP_CODE")
  359. strEnvConfig(&conf.NewRelicAppName, "IMGPROXY_NEW_RELIC_APP_NAME")
  360. strEnvConfig(&conf.NewRelicKey, "IMGPROXY_NEW_RELIC_KEY")
  361. strEnvConfig(&conf.PrometheusBind, "IMGPROXY_PROMETHEUS_BIND")
  362. strEnvConfig(&conf.PrometheusNamespace, "IMGPROXY_PROMETHEUS_NAMESPACE")
  363. strEnvConfig(&conf.BugsnagKey, "IMGPROXY_BUGSNAG_KEY")
  364. strEnvConfig(&conf.BugsnagStage, "IMGPROXY_BUGSNAG_STAGE")
  365. strEnvConfig(&conf.HoneybadgerKey, "IMGPROXY_HONEYBADGER_KEY")
  366. strEnvConfig(&conf.HoneybadgerEnv, "IMGPROXY_HONEYBADGER_ENV")
  367. strEnvConfig(&conf.SentryDSN, "IMGPROXY_SENTRY_DSN")
  368. strEnvConfig(&conf.SentryEnvironment, "IMGPROXY_SENTRY_ENVIRONMENT")
  369. strEnvConfig(&conf.SentryRelease, "IMGPROXY_SENTRY_RELEASE")
  370. boolEnvConfig(&conf.ReportDownloadingErrors, "IMGPROXY_REPORT_DOWNLOADING_ERRORS")
  371. boolEnvConfig(&conf.EnableDebugHeaders, "IMGPROXY_ENABLE_DEBUG_HEADERS")
  372. intEnvConfig(&conf.FreeMemoryInterval, "IMGPROXY_FREE_MEMORY_INTERVAL")
  373. intEnvConfig(&conf.DownloadBufferSize, "IMGPROXY_DOWNLOAD_BUFFER_SIZE")
  374. intEnvConfig(&conf.BufferPoolCalibrationThreshold, "IMGPROXY_BUFFER_POOL_CALIBRATION_THRESHOLD")
  375. if len(conf.Keys) != len(conf.Salts) {
  376. return fmt.Errorf("Number of keys and number of salts should be equal. Keys: %d, salts: %d", len(conf.Keys), len(conf.Salts))
  377. }
  378. if len(conf.Keys) == 0 {
  379. logWarning("No keys defined, so signature checking is disabled")
  380. conf.AllowInsecure = true
  381. }
  382. if len(conf.Salts) == 0 {
  383. logWarning("No salts defined, so signature checking is disabled")
  384. conf.AllowInsecure = true
  385. }
  386. if conf.SignatureSize < 1 || conf.SignatureSize > 32 {
  387. return fmt.Errorf("Signature size should be within 1 and 32, now - %d\n", conf.SignatureSize)
  388. }
  389. if len(conf.Bind) == 0 {
  390. return fmt.Errorf("Bind address is not defined")
  391. }
  392. if conf.ReadTimeout <= 0 {
  393. return fmt.Errorf("Read timeout should be greater than 0, now - %d\n", conf.ReadTimeout)
  394. }
  395. if conf.WriteTimeout <= 0 {
  396. return fmt.Errorf("Write timeout should be greater than 0, now - %d\n", conf.WriteTimeout)
  397. }
  398. if conf.KeepAliveTimeout < 0 {
  399. return fmt.Errorf("KeepAlive timeout should be greater than or equal to 0, now - %d\n", conf.KeepAliveTimeout)
  400. }
  401. if conf.DownloadTimeout <= 0 {
  402. return fmt.Errorf("Download timeout should be greater than 0, now - %d\n", conf.DownloadTimeout)
  403. }
  404. if conf.Concurrency <= 0 {
  405. return fmt.Errorf("Concurrency should be greater than 0, now - %d\n", conf.Concurrency)
  406. }
  407. if conf.MaxClients <= 0 {
  408. conf.MaxClients = conf.Concurrency * 10
  409. }
  410. if conf.TTL <= 0 {
  411. return fmt.Errorf("TTL should be greater than 0, now - %d\n", conf.TTL)
  412. }
  413. if conf.MaxSrcResolution <= 0 {
  414. return fmt.Errorf("Max src resolution should be greater than 0, now - %d\n", conf.MaxSrcResolution)
  415. }
  416. if conf.MaxSrcFileSize < 0 {
  417. return fmt.Errorf("Max src file size should be greater than or equal to 0, now - %d\n", conf.MaxSrcFileSize)
  418. }
  419. if conf.MaxAnimationFrames <= 0 {
  420. return fmt.Errorf("Max animation frames should be greater than 0, now - %d\n", conf.MaxAnimationFrames)
  421. }
  422. if conf.PngQuantizationColors < 2 {
  423. return fmt.Errorf("Png quantization colors should be greater than 1, now - %d\n", conf.PngQuantizationColors)
  424. } else if conf.PngQuantizationColors > 256 {
  425. return fmt.Errorf("Png quantization colors can't be greater than 256, now - %d\n", conf.PngQuantizationColors)
  426. }
  427. if conf.Quality <= 0 {
  428. return fmt.Errorf("Quality should be greater than 0, now - %d\n", conf.Quality)
  429. } else if conf.Quality > 100 {
  430. return fmt.Errorf("Quality can't be greater than 100, now - %d\n", conf.Quality)
  431. }
  432. if conf.IgnoreSslVerification {
  433. logWarning("Ignoring SSL verification is very unsafe")
  434. }
  435. if conf.LocalFileSystemRoot != "" {
  436. stat, err := os.Stat(conf.LocalFileSystemRoot)
  437. if err != nil {
  438. return fmt.Errorf("Cannot use local directory: %s", err)
  439. }
  440. if !stat.IsDir() {
  441. return fmt.Errorf("Cannot use local directory: not a directory")
  442. }
  443. if conf.LocalFileSystemRoot == "/" {
  444. logWarning("Exposing root via IMGPROXY_LOCAL_FILESYSTEM_ROOT is unsafe")
  445. }
  446. }
  447. if _, ok := os.LookupEnv("IMGPROXY_USE_GCS"); !ok && len(conf.GCSKey) > 0 {
  448. logWarning("Set IMGPROXY_USE_GCS to true since it may be required by future versions to enable GCS support")
  449. conf.GCSEnabled = true
  450. }
  451. if conf.WatermarkOpacity <= 0 {
  452. return fmt.Errorf("Watermark opacity should be greater than 0")
  453. } else if conf.WatermarkOpacity > 1 {
  454. return fmt.Errorf("Watermark opacity should be less than or equal to 1")
  455. }
  456. if conf.FallbackImageHTTPCode < 100 || conf.FallbackImageHTTPCode > 599 {
  457. return fmt.Errorf("Fallback image HTTP code should be between 100 and 599")
  458. }
  459. if len(conf.PrometheusBind) > 0 && conf.PrometheusBind == conf.Bind {
  460. return fmt.Errorf("Can't use the same binding for the main server and Prometheus")
  461. }
  462. if conf.FreeMemoryInterval <= 0 {
  463. return fmt.Errorf("Free memory interval should be greater than zero")
  464. }
  465. if conf.DownloadBufferSize < 0 {
  466. return fmt.Errorf("Download buffer size should be greater than or equal to 0")
  467. } else if conf.DownloadBufferSize > math.MaxInt32 {
  468. return fmt.Errorf("Download buffer size can't be greater than %d", math.MaxInt32)
  469. }
  470. if conf.BufferPoolCalibrationThreshold < 64 {
  471. return fmt.Errorf("Buffer pool calibration threshold should be greater than or equal to 64")
  472. }
  473. return nil
  474. }