Skip to content

Commit

Permalink
feat(cryptdConnectionString): makes mongocryptd uri configurable (#2049)
Browse files Browse the repository at this point in the history
* perf(cryptdConnectionString): make mongocryptd uri configurable by creating the property `autoEncryption.extraOptions.mongocryptURI`

Fixes NODE-2012
  • Loading branch information
rosemaryy authored and daprahamian committed Aug 13, 2019
1 parent d6f7e14 commit a487be4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/mongo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const closeOperation = require('./operations/mongo_client_ops').closeOperation;
* @property {string} [kmsProviders.local.key] The master key used to encrypt/decrypt data keys
* @property {object} [schemaMap] A map of namespaces to a local JSON schema for encryption
* @property {boolean} [bypassAutoEncryption] Allows the user to bypass auto encryption, maintaining implicit decryption
* @param {string} [extraOptions.mongocryptURI] A local process the driver communicates with to determine how to encrypt values in a command. Defaults to "mongodb://%2Fvar%2Fmongocryptd.sock" if domain sockets are available or "mongodb://localhost:27020" otherwise.
*/

/**
Expand Down
12 changes: 8 additions & 4 deletions lib/operations/mongo_client_ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,14 @@ function createTopology(mongoClient, topologyType, options, callback) {
}

const MongoClient = loadClient();
const connectionString =
os.platform() === 'win32'
? 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000'
: 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000';
let connectionString;
if (options.autoEncryption.extraOptions && options.autoEncryption.extraOptions.mongocryptURI) {
connectionString = options.autoEncryption.extraOptions.mongocryptURI;
} else if (os.platform() === 'win32') {
connectionString = 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000';
} else {
connectionString = 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000';
}

const mongocryptdClient = new MongoClient(connectionString, { useUnifiedTopology: true });
mongocryptdClient.connect(err => {
Expand Down

0 comments on commit a487be4

Please sign in to comment.