Skip to content

Commit 0b7551b

Browse files
PR requested changes
1 parent 9002ce2 commit 0b7551b

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

src/mongo_client.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ import type { SrvPoller } from './sdam/srv_polling';
3333
import { Topology, type TopologyEvents } from './sdam/topology';
3434
import { ClientSession, type ClientSessionOptions, ServerSessionPool } from './sessions';
3535
import {
36+
COSMOS_DB_CHECK,
37+
COSMOS_DB_MSG,
38+
DOCUMENT_DB_CHECK,
39+
DOCUMENT_DB_MSG,
3640
type HostAddress,
3741
hostMatchesWildcards,
42+
isHostMatch,
3843
type MongoDBNamespace,
3944
ns,
4045
resolveOptions
@@ -367,40 +372,27 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
367372
this.checkForNonGenuineHosts();
368373
}
369374

370-
DOCUMENT_DB_CHECK = /(\.docdb\.amazonaws\.com$)|(\.docdb-elastic\.amazonaws\.com$)/;
371-
COSMOS_DB_CHECK = /\.cosmos\.azure\.com$/;
372-
373-
static DOCUMENT_DB_MSG =
374-
'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb';
375-
static COSMOS_DB_MSG =
376-
'You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb';
377-
378-
/** @internal */
379-
private isHostMatch(match: RegExp, host?: string): boolean {
380-
return host && match.test(host.toLowerCase()) ? true : false;
381-
}
382-
383375
/** @internal */
384376
private checkForNonGenuineHosts() {
385377
if (this.mongoLogger && this.mongoLogger.logDestination) {
386378
const documentDBHostnames = this[kOptions].hosts.filter((hostAddress: HostAddress) =>
387-
this.isHostMatch(this.DOCUMENT_DB_CHECK, hostAddress.host)
379+
isHostMatch(DOCUMENT_DB_CHECK, hostAddress.host)
388380
);
389381

390-
const srvHostIsDocumentDB = this.isHostMatch(this.DOCUMENT_DB_CHECK, this[kOptions].srvHost);
382+
const srvHostIsDocumentDB = isHostMatch(DOCUMENT_DB_CHECK, this[kOptions].srvHost);
391383

392384
if (documentDBHostnames.length !== 0 || srvHostIsDocumentDB) {
393-
this.mongoLogger.info('client', MongoClient.DOCUMENT_DB_MSG);
385+
this.mongoLogger.info('client', DOCUMENT_DB_MSG);
394386
}
395387

396388
const cosmosDBHostnames = this[kOptions].hosts.filter((hostAddress: HostAddress) =>
397-
this.isHostMatch(this.COSMOS_DB_CHECK, hostAddress.host)
389+
isHostMatch(COSMOS_DB_CHECK, hostAddress.host)
398390
);
399391

400-
const srvHostIsCosmosDB = this.isHostMatch(this.COSMOS_DB_CHECK, this[kOptions].srvHost);
392+
const srvHostIsCosmosDB = isHostMatch(COSMOS_DB_CHECK, this[kOptions].srvHost);
401393

402394
if (cosmosDBHostnames.length !== 0 || srvHostIsCosmosDB) {
403-
this.mongoLogger.info('client', MongoClient.COSMOS_DB_MSG);
395+
this.mongoLogger.info('client', COSMOS_DB_MSG);
404396
}
405397
}
406398
}

src/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,3 +1282,20 @@ export class TimeoutController extends AbortController {
12821282
this.timeoutId = null;
12831283
}
12841284
}
1285+
1286+
/** @internal */
1287+
export const DOCUMENT_DB_CHECK = /(\.docdb\.amazonaws\.com$)|(\.docdb-elastic\.amazonaws\.com$)/;
1288+
/** @internal */
1289+
export const COSMOS_DB_CHECK = /\.cosmos\.azure\.com$/;
1290+
1291+
/** @internal */
1292+
export const DOCUMENT_DB_MSG =
1293+
'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb';
1294+
/** @internal */
1295+
export const COSMOS_DB_MSG =
1296+
'You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb';
1297+
1298+
/** @internal */
1299+
export function isHostMatch(match: RegExp, host?: string): boolean {
1300+
return host && match.test(host.toLowerCase()) ? true : false;
1301+
}

test/unit/connection_string.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { inspect } from 'util';
99
import {
1010
AUTH_MECHS_AUTH_SRC_EXTERNAL,
1111
AuthMechanism,
12+
COSMOS_DB_MSG,
1213
DEFAULT_ALLOWED_HOSTS,
14+
DOCUMENT_DB_MSG,
1315
FEATURE_FLAGS,
1416
type Log,
1517
MongoAPIError,
@@ -894,20 +896,22 @@ describe('Connection String', function () {
894896
});
895897

896898
const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger');
897-
const docDBmsg = MongoClient.DOCUMENT_DB_MSG;
898-
const cosmosDBmsg = MongoClient.COSMOS_DB_MSG;
899899
const test_cases = [
900900
['non-SRV example uri', 'mongodb://a.example.com:27017,b.example.com:27017/', ''],
901901
['non-SRV default uri', 'mongodb://a.mongodb.net:27017', ''],
902902
['SRV example uri', 'mongodb+srv://a.example.com/', ''],
903903
['SRV default uri', 'mongodb+srv://a.mongodb.net/', ''],
904904
// ensure case insensitity
905-
['non-SRV cosmosDB uri', 'mongodb://a.mongo.COSmos.aZure.com:19555/', cosmosDBmsg],
906-
['non-SRV documentDB uri', 'mongodb://a.docDB.AmazonAws.com:27017/', docDBmsg],
907-
['non-SRV documentDB uri ', 'mongodb://a.docdB-eLasTic.amazonaws.com:27017/', docDBmsg],
908-
['SRV cosmosDB uri', 'mongodb+srv://a.mongo.COSmos.aZure.com/', cosmosDBmsg],
909-
['SRV documentDB uri', 'mongodb+srv://a.docDB.AmazonAws.com/', docDBmsg],
910-
['SRV documentDB uri 2', 'mongodb+srv://a.docdB-eLastic.amazonaws.com/', docDBmsg]
905+
['non-SRV cosmosDB uri', 'mongodb://a.mongo.COSmos.aZure.com:19555/', COSMOS_DB_MSG],
906+
['non-SRV documentDB uri', 'mongodb://a.docDB.AmazonAws.com:27017/', DOCUMENT_DB_MSG],
907+
[
908+
'non-SRV documentDB uri ',
909+
'mongodb://a.docdB-eLasTic.amazonaws.com:27017/',
910+
DOCUMENT_DB_MSG
911+
],
912+
['SRV cosmosDB uri', 'mongodb+srv://a.mongo.COSmos.aZure.com/', COSMOS_DB_MSG],
913+
['SRV documentDB uri', 'mongodb+srv://a.docDB.AmazonAws.com/', DOCUMENT_DB_MSG],
914+
['SRV documentDB uri 2', 'mongodb+srv://a.docdB-eLastic.amazonaws.com/', DOCUMENT_DB_MSG]
911915
];
912916

913917
context('when logging is turned on', () => {

0 commit comments

Comments
 (0)