Skip to content

Commit a487be4

Browse files
rosemaryydaprahamian
authored andcommitted
feat(cryptdConnectionString): makes mongocryptd uri configurable (#2049)
* perf(cryptdConnectionString): make mongocryptd uri configurable by creating the property `autoEncryption.extraOptions.mongocryptURI` Fixes NODE-2012
1 parent d6f7e14 commit a487be4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/mongo_client.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const closeOperation = require('./operations/mongo_client_ops').closeOperation;
6767
* @property {string} [kmsProviders.local.key] The master key used to encrypt/decrypt data keys
6868
* @property {object} [schemaMap] A map of namespaces to a local JSON schema for encryption
6969
* @property {boolean} [bypassAutoEncryption] Allows the user to bypass auto encryption, maintaining implicit decryption
70+
* @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.
7071
*/
7172

7273
/**

lib/operations/mongo_client_ops.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,14 @@ function createTopology(mongoClient, topologyType, options, callback) {
439439
}
440440

441441
const MongoClient = loadClient();
442-
const connectionString =
443-
os.platform() === 'win32'
444-
? 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000'
445-
: 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000';
442+
let connectionString;
443+
if (options.autoEncryption.extraOptions && options.autoEncryption.extraOptions.mongocryptURI) {
444+
connectionString = options.autoEncryption.extraOptions.mongocryptURI;
445+
} else if (os.platform() === 'win32') {
446+
connectionString = 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000';
447+
} else {
448+
connectionString = 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000';
449+
}
446450

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

0 commit comments

Comments
 (0)