overleaf/services/filestore/test/acceptance/js/TestConfig.js

114 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2020-02-12 06:01:51 -05:00
const Path = require('path')
// use functions to get a fresh copy, not a reference, each time
function s3Config() {
return {
key: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY,
endpoint: process.env.AWS_S3_ENDPOINT,
pathStyle: true,
2021-07-13 07:04:46 -04:00
partSize: 100 * 1024 * 1024,
2020-02-12 06:01:51 -05:00
}
}
function s3Stores() {
return {
user_files: process.env.AWS_S3_USER_FILES_BUCKET_NAME,
template_files: process.env.AWS_S3_TEMPLATE_FILES_BUCKET_NAME,
2021-07-13 07:04:46 -04:00
public_files: process.env.AWS_S3_PUBLIC_FILES_BUCKET_NAME,
2020-02-12 06:01:51 -05:00
}
}
function gcsConfig() {
return {
endpoint: {
apiEndpoint: process.env.GCS_API_ENDPOINT,
apiScheme: process.env.GCS_API_SCHEME,
2021-07-13 07:04:46 -04:00
projectId: 'fake',
},
directoryKeyRegex: new RegExp('^[0-9a-fA-F]{24}/[0-9a-fA-F]{24}'),
unlockBeforeDelete: false, // fake-gcs does not support this
2021-07-13 07:04:46 -04:00
deletedBucketSuffix: '-deleted',
2020-02-12 06:01:51 -05:00
}
}
function gcsStores() {
return {
user_files: process.env.GCS_USER_FILES_BUCKET_NAME,
template_files: process.env.GCS_TEMPLATE_FILES_BUCKET_NAME,
2021-07-13 07:04:46 -04:00
public_files: process.env.GCS_PUBLIC_FILES_BUCKET_NAME,
2020-02-12 06:01:51 -05:00
}
}
function fsStores() {
return {
user_files: Path.resolve(__dirname, '../../../user_files'),
public_files: Path.resolve(__dirname, '../../../public_files'),
2021-07-13 07:04:46 -04:00
template_files: Path.resolve(__dirname, '../../../template_files'),
2020-02-12 06:01:51 -05:00
}
}
function fallbackStores(primaryConfig, fallbackConfig) {
return {
[primaryConfig.user_files]: fallbackConfig.user_files,
[primaryConfig.public_files]: fallbackConfig.public_files,
2021-07-13 07:04:46 -04:00
[primaryConfig.template_files]: fallbackConfig.template_files,
2020-02-12 06:01:51 -05:00
}
}
module.exports = {
FSPersistor: {
backend: 'fs',
2021-07-13 07:04:46 -04:00
stores: fsStores(),
2020-02-12 06:01:51 -05:00
},
S3Persistor: {
backend: 's3',
s3: s3Config(),
2021-07-13 07:04:46 -04:00
stores: s3Stores(),
2020-02-12 06:01:51 -05:00
},
GcsPersistor: {
backend: 'gcs',
gcs: gcsConfig(),
2021-07-13 07:04:46 -04:00
stores: gcsStores(),
2020-02-12 06:01:51 -05:00
},
FallbackS3ToFSPersistor: {
backend: 's3',
s3: s3Config(),
stores: s3Stores(),
fallback: {
backend: 'fs',
2021-07-13 07:04:46 -04:00
buckets: fallbackStores(s3Stores(), fsStores()),
},
2020-02-12 06:01:51 -05:00
},
FallbackFSToS3Persistor: {
backend: 'fs',
s3: s3Config(),
stores: fsStores(),
fallback: {
backend: 's3',
2021-07-13 07:04:46 -04:00
buckets: fallbackStores(fsStores(), s3Stores()),
},
2020-02-12 06:01:51 -05:00
},
FallbackGcsToS3Persistor: {
backend: 'gcs',
gcs: gcsConfig(),
stores: gcsStores(),
s3: s3Config(),
fallback: {
backend: 's3',
2021-07-13 07:04:46 -04:00
buckets: fallbackStores(gcsStores(), s3Stores()),
},
2020-02-12 06:01:51 -05:00
},
FallbackS3ToGcsPersistor: {
backend: 's3',
// can use the same bucket names for gcs and s3 (in tests)
stores: s3Stores(),
s3: s3Config(),
gcs: gcsConfig(),
fallback: {
backend: 'gcs',
2021-07-13 07:04:46 -04:00
buckets: fallbackStores(s3Stores(), gcsStores()),
},
},
2020-02-12 06:01:51 -05:00
}