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

fix: restore createAutoEncrypter() functionality #2710

Merged
merged 1 commit into from
Jan 22, 2021
Merged
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
2 changes: 1 addition & 1 deletion src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export function parseOptions(

checkTLSOptions(mongoOptions);
if (mongoClient && options.autoEncryption) {
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient);
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient, options);
}
if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);

Expand Down
17 changes: 11 additions & 6 deletions src/operations/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolveSRVRecord } from '../connection_string';
import { emitDeprecationWarning, Callback } from '../utils';
import { CMAP_EVENT_NAMES } from '../cmap/events';
import * as BSON from '../bson';
import type { MongoClient, MongoOptions } from '../mongo_client';
import type { MongoClient, MongoOptions, MongoClientOptions } from '../mongo_client';
import { Connection } from '../cmap/connection';
import { Server } from '../sdam/server';
import type { AutoEncrypter } from '../deps';
Expand Down Expand Up @@ -114,8 +114,11 @@ function registerDeprecatedEventNotifiers(client: MongoClient) {
* returns undefined if CSFLE is not enabled.
* @throws if optional 'mongodb-client-encryption' dependency missing
*/
export function createAutoEncrypter(client: MongoClient): AutoEncrypter | undefined {
if (!client.options.autoEncryption) {
export function createAutoEncrypter(
client: MongoClient,
options: MongoClientOptions
): AutoEncrypter | undefined {
if (!options.autoEncryption) {
return;
}
try {
Expand All @@ -135,10 +138,12 @@ export function createAutoEncrypter(client: MongoClient): AutoEncrypter | undefi
'Please make sure you are loading the correct version of `mongodb-client-encryption`'
);
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { AutoEncrypterClass } = mongodbClientEncryption.extension(require('../../lib/index'));
const { AutoEncrypter: AutoEncrypterClass } = mongodbClientEncryption.extension(
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../lib/index')
);

const mongoCryptOptions = Object.assign({ bson: BSON }, client.options.autoEncryption);
const mongoCryptOptions = Object.assign({ bson: BSON }, options.autoEncryption);
return new AutoEncrypterClass(client, mongoCryptOptions);
}

Expand Down