|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const os = require('os'); |
4 | 3 | const OperationBase = require('./operation').OperationBase;
|
5 | 4 | const defineAspects = require('./operation').defineAspects;
|
6 | 5 | const Aspect = require('./operation').Aspect;
|
@@ -482,35 +481,16 @@ function createTopology(mongoClient, topologyType, options, callback) {
|
482 | 481 | return;
|
483 | 482 | }
|
484 | 483 | try {
|
485 |
| - AutoEncrypter = require('mongodb-client-encryption').AutoEncrypter; |
| 484 | + AutoEncrypter = require('mongodb-client-encryption')(require('../../index')).AutoEncrypter; |
486 | 485 | } catch (err) {
|
487 | 486 | callback(err);
|
488 | 487 | return;
|
489 | 488 | }
|
490 | 489 |
|
491 |
| - const MongoClient = loadClient(); |
492 |
| - let connectionString; |
493 |
| - if (options.autoEncryption.extraOptions && options.autoEncryption.extraOptions.mongocryptURI) { |
494 |
| - connectionString = options.autoEncryption.extraOptions.mongocryptURI; |
495 |
| - } else if (os.platform() === 'win32') { |
496 |
| - connectionString = 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000'; |
497 |
| - } else { |
498 |
| - connectionString = 'mongodb://%2Ftmp%2Fmongocryptd.sock/?serverSelectionTimeoutMS=1000'; |
499 |
| - } |
500 |
| - |
501 |
| - const mongocryptdClient = new MongoClient(connectionString, { |
502 |
| - useNewUrlParser: true, |
503 |
| - useUnifiedTopology: true |
504 |
| - }); |
505 |
| - mongoClient.s.mongocryptdClient = mongocryptdClient; |
506 |
| - mongocryptdClient.connect(err => { |
| 490 | + const mongoCryptOptions = Object.assign({}, options.autoEncryption); |
| 491 | + topology.s.options.autoEncrypter = new AutoEncrypter(mongoClient, mongoCryptOptions); |
| 492 | + topology.s.options.autoEncrypter.init(err => { |
507 | 493 | if (err) return callback(err, null);
|
508 |
| - |
509 |
| - const mongoCryptOptions = Object.assign({}, options.autoEncryption, { |
510 |
| - mongocryptdClient |
511 |
| - }); |
512 |
| - |
513 |
| - topology.s.options.autoEncrypter = new AutoEncrypter(mongoClient, mongoCryptOptions); |
514 | 494 | callback(null, newTopology);
|
515 | 495 | });
|
516 | 496 | });
|
|
0 commit comments