Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support documentdb #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/external-db-config/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/external-db-config/lib/utils/config_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
4 changes: 3 additions & 1 deletion packages/external-db-mongo/lib/connection_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
25 changes: 25 additions & 0 deletions packages/external-db-mongo/lib/documentdb_utils.js
Original file line number Diff line number Diff line change
@@ -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 }
4 changes: 4 additions & 0 deletions packages/velo-external-db/lib/storage/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down