config.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. const convict = require('convict');
  2. const { tmpdir } = require('os');
  3. const path = require('path');
  4. const { randomBytes } = require('crypto');
  5. const conf = convict({
  6. s3_bucket: {
  7. format: String,
  8. default: '',
  9. env: 'S3_BUCKET'
  10. },
  11. s3_endpoint: {
  12. format: String,
  13. default: '',
  14. env: 'S3_ENDPOINT'
  15. },
  16. s3_use_path_style_endpoint: {
  17. format: Boolean,
  18. default: false,
  19. env: 'S3_USE_PATH_STYLE_ENDPOINT'
  20. },
  21. gcs_bucket: {
  22. format: String,
  23. default: '',
  24. env: 'GCS_BUCKET'
  25. },
  26. expire_times_seconds: {
  27. format: Array,
  28. default: [300, 3600, 86400, 604800],
  29. env: 'EXPIRE_TIMES_SECONDS'
  30. },
  31. default_expire_seconds: {
  32. format: Number,
  33. default: 86400,
  34. env: 'DEFAULT_EXPIRE_SECONDS'
  35. },
  36. max_expire_seconds: {
  37. format: Number,
  38. default: 86400 * 7,
  39. env: 'MAX_EXPIRE_SECONDS'
  40. },
  41. anon_max_expire_seconds: {
  42. format: Number,
  43. default: 86400,
  44. env: 'ANON_MAX_EXPIRE_SECONDS'
  45. },
  46. download_counts: {
  47. format: Array,
  48. default: [1, 2, 3, 4, 5, 20, 50, 100],
  49. env: 'DOWNLOAD_COUNTS'
  50. },
  51. max_downloads: {
  52. format: Number,
  53. default: 100,
  54. env: 'MAX_DOWNLOADS'
  55. },
  56. anon_max_downloads: {
  57. format: Number,
  58. default: 5,
  59. env: 'ANON_MAX_DOWNLOADS'
  60. },
  61. max_files_per_archive: {
  62. format: Number,
  63. default: 64,
  64. env: 'MAX_FILES_PER_ARCHIVE'
  65. },
  66. max_archives_per_user: {
  67. format: Number,
  68. default: 16,
  69. env: 'MAX_ARCHIVES_PER_USER'
  70. },
  71. redis_host: {
  72. format: String,
  73. default: 'localhost',
  74. env: 'REDIS_HOST'
  75. },
  76. redis_event_expire: {
  77. format: Boolean,
  78. default: false,
  79. env: 'REDIS_EVENT_EXPIRE'
  80. },
  81. redis_retry_time: {
  82. format: Number,
  83. default: 10000,
  84. env: 'REDIS_RETRY_TIME'
  85. },
  86. redis_retry_delay: {
  87. format: Number,
  88. default: 500,
  89. env: 'REDIS_RETRY_DELAY'
  90. },
  91. listen_address: {
  92. format: 'ipaddress',
  93. default: '0.0.0.0',
  94. env: 'IP_ADDRESS'
  95. },
  96. listen_port: {
  97. format: 'port',
  98. default: 1443,
  99. arg: 'port',
  100. env: 'PORT'
  101. },
  102. amplitude_id: {
  103. format: String,
  104. default: '',
  105. env: 'AMPLITUDE_ID'
  106. },
  107. analytics_id: {
  108. format: String,
  109. default: '',
  110. env: 'GOOGLE_ANALYTICS_ID'
  111. },
  112. sentry_id: {
  113. format: String,
  114. default: '',
  115. env: 'SENTRY_CLIENT'
  116. },
  117. sentry_dsn: {
  118. format: String,
  119. default: '',
  120. env: 'SENTRY_DSN'
  121. },
  122. env: {
  123. format: ['production', 'development', 'test'],
  124. default: 'development',
  125. env: 'NODE_ENV'
  126. },
  127. max_file_size: {
  128. format: Number,
  129. default: 1024 * 1024 * 1024 * 2.5,
  130. env: 'MAX_FILE_SIZE'
  131. },
  132. anon_max_file_size: {
  133. format: Number,
  134. default: 1024 * 1024 * 1024,
  135. env: 'ANON_MAX_FILE_SIZE'
  136. },
  137. l10n_dev: {
  138. format: Boolean,
  139. default: false,
  140. env: 'L10N_DEV'
  141. },
  142. base_url: {
  143. format: 'url',
  144. default: 'https://send.firefox.com',
  145. env: 'BASE_URL'
  146. },
  147. file_dir: {
  148. format: 'String',
  149. default: `${tmpdir()}${path.sep}send-${randomBytes(4).toString('hex')}`,
  150. env: 'FILE_DIR'
  151. },
  152. fxa_url: {
  153. format: 'url',
  154. default: 'https://send-fxa.dev.lcip.org',
  155. env: 'FXA_URL'
  156. },
  157. fxa_client_id: {
  158. format: String,
  159. default: '', // disabled
  160. env: 'FXA_CLIENT_ID'
  161. },
  162. fxa_key_scope: {
  163. format: String,
  164. default: 'https://identity.mozilla.com/apps/send',
  165. env: 'FXA_KEY_SCOPE'
  166. },
  167. fxa_csp_oauth_url: {
  168. format: String,
  169. default: '',
  170. env: 'FXA_CSP_OAUTH_URL'
  171. },
  172. fxa_csp_content_url: {
  173. format: String,
  174. default: '',
  175. env: 'FXA_CSP_CONTENT_URL'
  176. },
  177. fxa_csp_profile_url: {
  178. format: String,
  179. default: '',
  180. env: 'FXA_CSP_PROFILE_URL'
  181. },
  182. fxa_csp_profileimage_url: {
  183. format: String,
  184. default: '',
  185. env: 'FXA_CSP_PROFILEIMAGE_URL'
  186. },
  187. survey_url: {
  188. format: String,
  189. default: '',
  190. env: 'SURVEY_URL'
  191. },
  192. ip_db: {
  193. format: String,
  194. default: '',
  195. env: 'IP_DB'
  196. }
  197. });
  198. // Perform validation
  199. conf.validate({ allowed: 'strict' });
  200. const props = conf.getProperties();
  201. module.exports = props;