TestConfig.js 3.0 KB

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