Skip to content

Commit

Permalink
Remove unused or alias options
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Nov 18, 2020
1 parent 167850d commit 0875e3a
Show file tree
Hide file tree
Showing 62 changed files with 808 additions and 1,045 deletions.
34 changes: 34 additions & 0 deletions src/cmap/auth/mongo_credentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Resolves the default auth mechanism according to

import type { Document } from '../../bson';
import { MongoParseError } from '../../error';
import { AuthMechanism, AuthMechanismEnum } from './defaultAuthProviders';

// https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst
Expand Down Expand Up @@ -108,4 +109,37 @@ export class MongoCredentials {

return this;
}

validate(): void {
if (
(this.mechanism === 'GSSAPI' ||
this.mechanism === 'MONGODB-CR' ||
this.mechanism === 'PLAIN' ||
this.mechanism === 'SCRAM-SHA-1' ||
this.mechanism === 'SCRAM-SHA-256') &&
!this.username
) {
throw new MongoParseError(`Username required for mechanism '${this.mechanism}'`);
}

if (
this.mechanism === 'GSSAPI' ||
this.mechanism === 'MONGODB-AWS' ||
this.mechanism === 'MONGODB-X509'
) {
if (this.source != null && this.source !== '$external') {
throw new MongoParseError(
`Invalid source '${this.source}' for mechanism '${this.mechanism}' specified.`
);
}
}

if (this.mechanism === 'PLAIN' && this.source == null) {
throw new MongoParseError('PLAIN Authentication Mechanism needs an auth source');
}

if (this.mechanism === 'MONGODB-X509' && this.password != null) {
throw new MongoParseError(`Password not allowed for mechanism MONGODB-X509`);
}
}
}
10 changes: 7 additions & 3 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,13 @@ function assertRepelOptions(options: AnyOptions, optionKeyA: string, optionKeyB:
* @param options - The options used for options parsing
* @throws MongoParseError if TLS options are invalid
*/
function checkTLSOptions(options: AnyOptions) {
if (!options) return null;
const check = (a: any, b: any) => assertRepelOptions(options, a, b);
export function checkTLSOptions(options: AnyOptions): void {
if (!options) return;
const check = (a: string, b: string) => {
if (Reflect.has(options, a) && Reflect.has(options, b)) {
throw new MongoParseError(`The '${a}' option cannot be used with '${b}'`);
}
};
check('tlsInsecure', 'tlsAllowInvalidCertificates');
check('tlsInsecure', 'tlsAllowInvalidHostnames');
check('tlsInsecure', 'tlsDisableCertificateRevocationCheck');
Expand Down
1 change: 0 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const legalOptionNames = [
'pkFactory',
'serializeFunctions',
'raw',
'bufferMaxEntries',
'authSource',
'ignoreUndefined',
'promoteLongs',
Expand Down
8 changes: 4 additions & 4 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export interface MongoURIOptions extends Pick<WriteConcernOptions, 'journal' | '
serverSelectionTryOnce?: boolean;
/** heartbeatFrequencyMS controls when the driver checks the state of the MongoDB deployment. Specify the interval (in milliseconds) between checks, counted from the end of the previous check until the beginning of the next one. */
heartbeatFrequencyMS?: number;
/** Sets the minimum heartbeat frequency. In the event that the driver has to frequently re-check a server's availability, it will wait at least this long since the previous check to avoid wasted effort. */
minHeartbeatFrequencyMS?: number;
/** The name of the application that created this MongoClient instance. MongoDB 3.4 and newer will print this value in the server log upon establishing each connection. It is also recorded in the slow query log and profile collections */
appName?: string;
/** Enables retryable reads. */
Expand All @@ -142,8 +144,6 @@ export interface MongoClientOptions
extends WriteConcernOptions,
MongoURIOptions,
BSONSerializeOptions {
/** The maximum number of connections in the connection pool. */
poolSize?: MongoURIOptions['maxPoolSize'];
/** Validate mongod server certificate against Certificate Authority */
sslValidate?: boolean;
/** SSL Certificate store binary buffer. */
Expand Down Expand Up @@ -192,8 +192,6 @@ export interface MongoClientOptions
numberOfRetries?: number;
/** Enable command monitoring for this client */
monitorCommands?: boolean;
/** If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections */
minSize?: number;
/** Optionally enable client side auto encryption */
autoEncryption?: AutoEncryptionOptions;
/** Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver */
Expand All @@ -202,6 +200,8 @@ export interface MongoClientOptions
servername?: string;

dbName?: string;
username?: string;
password?: string;
}

/** @public */
Expand Down
3 changes: 0 additions & 3 deletions src/operations/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const validOptionNames = [
'serializeFunctions',
'ignoreUndefined',
'raw',
'bufferMaxEntries',
'readPreference',
'pkFactory',
'promiseLibrary',
Expand Down Expand Up @@ -88,7 +87,6 @@ const validOptionNames = [
'retryReads',
'useNewUrlParser',
'serverSelectionTimeoutMS',
'useRecoveryToken',
'autoEncryption',
'driverInfo',
'tls',
Expand Down Expand Up @@ -219,7 +217,6 @@ export function connect(
if (finalOptions.socketTimeoutMS == null) finalOptions.socketTimeoutMS = 0;
if (finalOptions.connectTimeoutMS == null) finalOptions.connectTimeoutMS = 10000;
if (finalOptions.retryWrites == null) finalOptions.retryWrites = true;
if (finalOptions.useRecoveryToken == null) finalOptions.useRecoveryToken = true;
if (finalOptions.readPreference == null) finalOptions.readPreference = 'primary';

if (finalOptions.db_options && finalOptions.db_options.auth) {
Expand Down
5 changes: 1 addition & 4 deletions src/sdam/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ export const TOPOLOGY_DEFAULTS = {
localThresholdMS: 15,
serverSelectionTimeoutMS: 30000,
heartbeatFrequencyMS: 10000,
minHeartbeatFrequencyMS: 500,

// TODO: remove in v4
useRecoveryToken: true
minHeartbeatFrequencyMS: 500
};

/** @internal */
Expand Down
1 change: 0 additions & 1 deletion src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export interface TopologyOptions extends ServerOptions, BSONSerializeOptions, Lo
directConnection: boolean;

metadata: ClientMetadata;
useRecoveryToken: boolean;
}

/** @public */
Expand Down
10 changes: 1 addition & 9 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,8 @@ function endTransaction(session: ClientSession, commandName: string, callback: C
callback(e, r);
}

if (
if (session.transaction.recoveryToken) {
// Assumption here that commandName is "commitTransaction" or "abortTransaction"
session.transaction.recoveryToken &&
supportsRecoveryToken(session)
) {
command.recoveryToken = session.transaction.recoveryToken;
}

Expand Down Expand Up @@ -580,11 +577,6 @@ function endTransaction(session: ClientSession, commandName: string, callback: C
);
}

function supportsRecoveryToken(session: ClientSession) {
const topology = session.topology;
return !!topology.s.options.useRecoveryToken;
}

/** @internal */
export type ServerSessionId = { id: Binary };

Expand Down
36 changes: 18 additions & 18 deletions test/functional/aggregation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Aggregation', function () {
},

test: function (done) {
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 });
const client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 });

client.connect(function (err, client) {
expect(err).to.not.exist;
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -488,7 +488,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -578,7 +578,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -663,7 +663,7 @@ describe('Aggregation', function () {
},

test: function (done) {
var client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
var client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// LINE var MongoClient = require('mongodb').MongoClient;
Expand Down Expand Up @@ -751,7 +751,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

client.connect(function (err, client) {
Expand Down Expand Up @@ -804,7 +804,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

client.connect(function (err, client) {
Expand Down Expand Up @@ -864,7 +864,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

client.connect(function (err, client) {
Expand Down Expand Up @@ -939,7 +939,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

const testCases = [
Expand Down Expand Up @@ -1005,7 +1005,7 @@ describe('Aggregation', function () {
},

test: function (done) {
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }),
const client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 }),
databaseName = this.configuration.db;

// DOC_LINE var db = new Db('test', new Server('localhost', 27017));
Expand Down Expand Up @@ -1133,7 +1133,7 @@ describe('Aggregation', function () {
}
},
test: function (done) {
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 });
const client = this.configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
const databaseName = this.configuration.db;

const comment = 'Darmok and Jalad at Tanagra';
Expand Down Expand Up @@ -1176,7 +1176,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

// DOC_LINE var client = new MongoClient(new Server('localhost', 27017));
Expand Down Expand Up @@ -1243,7 +1243,7 @@ describe('Aggregation', function () {
test: function (done) {
var databaseName = this.configuration.db;
var client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1
maxPoolSize: 1
});

// DOC_LINE var client = new MongoClient(new Server('localhost', 27017));
Expand Down Expand Up @@ -1284,7 +1284,7 @@ describe('Aggregation', function () {
test: function (done) {
const databaseName = this.configuration.db;
const client = this.configuration.newClient(this.configuration.writeConcernMax(), {
poolSize: 1,
maxPoolSize: 1,
monitorCommands: true
});

Expand Down
Loading

0 comments on commit 0875e3a

Please sign in to comment.