TestConfig.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const Path = require('path')
  2. // use functions to get a fresh copy, not a reference, each time
  3. function s3Config() {
  4. return {
  5. key: process.env.AWS_ACCESS_KEY_ID,
  6. secret: process.env.AWS_SECRET_ACCESS_KEY,
  7. endpoint: process.env.AWS_S3_ENDPOINT,
  8. pathStyle: true,
  9. partSize: 100 * 1024 * 1024,
  10. }
  11. }
  12. function s3Stores() {
  13. return {
  14. user_files: process.env.AWS_S3_USER_FILES_BUCKET_NAME,
  15. template_files: process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME,
  16. public_files: process.env.AWS_S3_PUBLIC_FILES_BUCKET_NAME,
  17. }
  18. }
  19. function gcsConfig() {
  20. return {
  21. endpoint: {
  22. apiEndpoint: process.env.GCS_API_ENDPOINT,
  23. projectId: 'fake',
  24. },
  25. directoryKeyRegex: /^[0-9a-fA-F]{24}\/[0-9a-fA-F]{24}/,
  26. unlockBeforeDelete: false, // fake-gcs does not support this
  27. deletedBucketSuffix: '-deleted',
  28. }
  29. }
  30. function gcsStores() {
  31. return {
  32. user_files: process.env.GCS_USER_FILES_BUCKET_NAME,
  33. template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
  34. public_files: process.env.GCS_PUBLIC_FILES_BUCKET_NAME,
  35. }
  36. }
  37. function fsStores() {
  38. return {
  39. user_files: Path.resolve(__dirname, '../../../user_files'),
  40. public_files: Path.resolve(__dirname, '../../../public_files'),
  41. template_files: Path.resolve(__dirname, '../../../template_files'),
  42. }
  43. }
  44. function fallbackStores(primaryConfig, fallbackConfig) {
  45. return {
  46. [primaryConfig.user_files]: fallbackConfig.user_files,
  47. [primaryConfig.public_files]: fallbackConfig.public_files,
  48. [primaryConfig.template_files]: fallbackConfig.template_files,
  49. }
  50. }
  51. module.exports = {
  52. FSPersistor: {
  53. backend: 'fs',
  54. stores: fsStores(),
  55. },
  56. S3Persistor: {
  57. backend: 's3',
  58. s3: s3Config(),
  59. stores: s3Stores(),
  60. },
  61. GcsPersistor: {
  62. backend: 'gcs',
  63. gcs: gcsConfig(),
  64. stores: gcsStores(),
  65. },
  66. FallbackS3ToFSPersistor: {
  67. backend: 's3',
  68. s3: s3Config(),
  69. stores: s3Stores(),
  70. fallback: {
  71. backend: 'fs',
  72. buckets: fallbackStores(s3Stores(), fsStores()),
  73. },
  74. },
  75. FallbackFSToS3Persistor: {
  76. backend: 'fs',
  77. s3: s3Config(),
  78. stores: fsStores(),
  79. fallback: {
  80. backend: 's3',
  81. buckets: fallbackStores(fsStores(), s3Stores()),
  82. },
  83. },
  84. FallbackGcsToS3Persistor: {
  85. backend: 'gcs',
  86. gcs: gcsConfig(),
  87. stores: gcsStores(),
  88. s3: s3Config(),
  89. fallback: {
  90. backend: 's3',
  91. buckets: fallbackStores(gcsStores(), s3Stores()),
  92. },
  93. },
  94. FallbackS3ToGcsPersistor: {
  95. backend: 's3',
  96. // can use the same bucket names for gcs and s3 (in tests)
  97. stores: s3Stores(),
  98. s3: s3Config(),
  99. gcs: gcsConfig(),
  100. fallback: {
  101. backend: 'gcs',
  102. buckets: fallbackStores(s3Stores(), gcsStores()),
  103. },
  104. },
  105. }