diff --git a/packages/external-db-config/lib/factory.js b/packages/external-db-config/lib/factory.js index 9f23fbdd3..ac36f72d5 100644 --- a/packages/external-db-config/lib/factory.js +++ b/packages/external-db-config/lib/factory.js @@ -23,6 +23,7 @@ const create = () => { internalConfigReader = new aws.AwsDynamoConfigReader(region, secretId) break case 'mongo': + case 'documentdb': internalConfigReader = new aws.AwsMongoConfigReader(region, secretId) break default: diff --git a/packages/external-db-config/lib/utils/config_utils.js b/packages/external-db-config/lib/utils/config_utils.js index 5a7df0361..a761a5086 100644 --- a/packages/external-db-config/lib/utils/config_utils.js +++ b/packages/external-db-config/lib/utils/config_utils.js @@ -2,7 +2,7 @@ const objectContainsKey = (obj, key) => typeof obj[key] === 'string' && obj[key] const checkRequiredKeys = (obj, requiredKeys) => requiredKeys.filter(key => !objectContainsKey(obj, key)) -const supportedDBs = ['postgres', 'spanner', 'firestore', 'mssql', 'mysql', 'mongo', 'airtable', 'dynamodb', 'bigquery', 'google-sheets'] +const supportedDBs = ['postgres', 'spanner', 'firestore', 'mssql', 'mysql', 'mongo', 'airtable', 'dynamodb', 'bigquery', 'google-sheets', 'documentdb'] const supportedVendors = ['gcp', 'aws', 'azure'] diff --git a/packages/external-db-mongo/lib/connection_provider.js b/packages/external-db-mongo/lib/connection_provider.js index 6245c1fd3..2ded61d51 100644 --- a/packages/external-db-mongo/lib/connection_provider.js +++ b/packages/external-db-mongo/lib/connection_provider.js @@ -4,9 +4,11 @@ const DataProvider = require('./mongo_data_provider') const FilterParser = require('./sql_filter_transformer') const DatabaseOperations = require('./mongo_operations') const { notConnectedPool, emptyClient } = require('./mongo_utils') +const { documentDBConnectionOptions } = require('./documentdb_utils') const init = async(cfg) => { - const client = cfg.connectionUri ? new MongoClient(cfg.connectionUri) : emptyClient() + const { connectionUri, options } = cfg.documentDb ? await documentDBConnectionOptions(cfg, __dirname) : { connectionUri: cfg.connectionUri, options: {} } + const client = connectionUri ? new MongoClient(connectionUri, options) : emptyClient() const { pool, cleanup } = await client.connect() .then((res) => { diff --git a/packages/external-db-mongo/lib/documentdb_utils.js b/packages/external-db-mongo/lib/documentdb_utils.js new file mode 100644 index 000000000..1fd3007c8 --- /dev/null +++ b/packages/external-db-mongo/lib/documentdb_utils.js @@ -0,0 +1,25 @@ +const { URL } = require('url') +const https = require('https') +const fs = require('fs') + +const documentDBConnectionOptions = async(cfg, path) => { + return new Promise(resolve => { + const documentDbUri = new URL(cfg.connectionUri) + + if (documentDbUri.searchParams.get('ssl_ca_certs') === 'rds-combined-ca-bundle.pem') { + documentDbUri.searchParams.delete('ssl_ca_certs') + const file = fs.createWriteStream(`${path}/rds-combined-ca-bundle.pem`) + https.get('https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem', resp => resp.pipe(file)) + file.on('finish', () => resolve({ + connectionUri: documentDbUri.toString(), options: { tlsCAFile: `${path}/rds-combined-ca-bundle.pem` } + })) + } + + else { + resolve( { connectionUri: documentDbUri.toString(), options: {} }) + } + }) + +} + +module.exports = { documentDBConnectionOptions } \ No newline at end of file diff --git a/packages/velo-external-db/lib/storage/factory.js b/packages/velo-external-db/lib/storage/factory.js index 172bf737c..a9bdd01e2 100644 --- a/packages/velo-external-db/lib/storage/factory.js +++ b/packages/velo-external-db/lib/storage/factory.js @@ -53,6 +53,10 @@ const init = async(_type, vendor, config) => { const { init } = require('external-db-bigquery') return append(await init(cfg), cfg.secretKey) } + case 'documentdb': { + const { init } = require('external-db-mongo') + return append(await init({ ...cfg, documentDb: true }), cfg.secretKey) + } default: { const init = require('./stub-db/init') return append(await init(type), cfg.secretKey)