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 17, 2020
1 parent 41b4085 commit b661080
Show file tree
Hide file tree
Showing 63 changed files with 984 additions and 1,109 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 @@ -522,9 +522,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 @@ -124,6 +124,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 @@ -139,8 +141,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 @@ -189,8 +189,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 @@ -199,6 +197,8 @@ export interface MongoClientOptions
servername?: string;

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

/** @public */
Expand Down
Loading

0 comments on commit b661080

Please sign in to comment.