TestConfig.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. apiScheme: process.env.GCS_API_SCHEME,
  24. projectId: 'fake',
  25. },
  26. directoryKeyRegex: /^[0-9a-fA-F]{24}\/[0-9a-fA-F]{24}/,
  27. unlockBeforeDelete: false, // fake-gcs does not support this
  28. deletedBucketSuffix: '-deleted',
  29. }
  30. }
  31. function gcsStores() {
  32. return {
  33. user_files: process.env.GCS_USER_FILES_BUCKET_NAME,
  34. template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
  35. public_files: process.env.GCS_PUBLIC_FILES_BUCKET_NAME,
  36. }
  37. }
  38. function fsStores() {
  39. return {
  40. user_files: Path.resolve(__dirname, '../../../user_files'),
  41. public_files: Path.resolve(__dirname, '../../../public_files'),
  42. template_files: Path.resolve(__dirname, '../../../template_files'),
  43. }
  44. }
  45. function fallbackStores(primaryConfig, fallbackConfig) {
  46. return {
  47. [primaryConfig.user_files]: fallbackConfig.user_files,
  48. [primaryConfig.public_files]: fallbackConfig.public_files,
  49. [primaryConfig.template_files]: fallbackConfig.template_files,
  50. }
  51. }
  52. module.exports = {
  53. FSPersistor: {
  54. backend: 'fs',
  55. stores: fsStores(),
  56. },
  57. S3Persistor: {
  58. backend: 's3',
  59. s3: s3Config(),
  60. stores: s3Stores(),
  61. },
  62. GcsPersistor: {
  63. backend: 'gcs',
  64. gcs: gcsConfig(),
  65. stores: gcsStores(),
  66. },
  67. FallbackS3ToFSPersistor: {
  68. backend: 's3',
  69. s3: s3Config(),
  70. stores: s3Stores(),
  71. fallback: {
  72. backend: 'fs',
  73. buckets: fallbackStores(s3Stores(), fsStores()),
  74. },
  75. },
  76. FallbackFSToS3Persistor: {
  77. backend: 'fs',
  78. s3: s3Config(),
  79. stores: fsStores(),
  80. fallback: {
  81. backend: 's3',
  82. buckets: fallbackStores(fsStores(), s3Stores()),
  83. },
  84. },
  85. FallbackGcsToS3Persistor: {
  86. backend: 'gcs',
  87. gcs: gcsConfig(),
  88. stores: gcsStores(),
  89. s3: s3Config(),
  90. fallback: {
  91. backend: 's3',
  92. buckets: fallbackStores(gcsStores(), s3Stores()),
  93. },
  94. },
  95. FallbackS3ToGcsPersistor: {
  96. backend: 's3',
  97. // can use the same bucket names for gcs and s3 (in tests)
  98. stores: s3Stores(),
  99. s3: s3Config(),
  100. gcs: gcsConfig(),
  101. fallback: {
  102. backend: 'gcs',
  103. buckets: fallbackStores(s3Stores(), gcsStores()),
  104. },
  105. },
  106. }