Skip to content

Commit adfd307

Browse files
committed
Use identifyServerName instead of getGenuineMongoDB
1 parent 7852258 commit adfd307

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

packages/compass-connections/src/stores/connections-store-redux.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { getNotificationTriggers } from '../components/connection-status-notifications';
2929
import { openToast, showConfirmation } from '@mongodb-js/compass-components';
3030
import { adjustConnectionOptionsBeforeConnect } from '@mongodb-js/connection-form';
31-
import mongodbBuildInfo, { getGenuineMongoDB } from 'mongodb-build-info';
31+
import { isAtlasStream } from 'mongodb-build-info';
3232
import EventEmitter from 'events';
3333
import { showNonGenuineMongoDBWarningModal as _showNonGenuineMongoDBWarningModal } from '../components/non-genuine-connection-modal';
3434
import { showEndOfLifeMongoDBWarningModal as _showEndOfLifeMongoDBWarningModal } from '../components/end-of-life-connection-modal';
@@ -1416,13 +1416,13 @@ function isAtlasStreamsInstance(
14161416
adjustedConnectionInfoForConnection: ConnectionInfo
14171417
) {
14181418
try {
1419-
return mongodbBuildInfo.isAtlasStream(
1419+
return isAtlasStream(
14201420
adjustedConnectionInfoForConnection.connectionOptions.connectionString
14211421
);
14221422
} catch {
14231423
// This catch-all is not ideal, but it safe-guards regular connections
14241424
// instead of making assumptions on the fact that the implementation
1425-
// of `mongodbBuildInfo.isAtlasStream` would never throw.
1425+
// of `isAtlasStream` would never throw.
14261426
return false;
14271427
}
14281428
}
@@ -1888,10 +1888,7 @@ const connectWithOptions = (
18881888
connectionId: connectionInfo.id,
18891889
});
18901890

1891-
if (
1892-
getGenuineMongoDB(connectionInfo.connectionOptions.connectionString)
1893-
.isGenuine === false
1894-
) {
1891+
if (!instanceInfo.genuineMongoDB.isGenuine) {
18951892
dispatch(showNonGenuineMongoDBWarningModal(connectionInfo.id));
18961893
} else if (
18971894
await shouldShowEndOfLifeWarning(

packages/data-service/src/instance-detail-helper.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
} from 'mongodb';
88
import {
99
isEnterprise,
10-
getGenuineMongoDB,
10+
identifyServerName,
1111
getDataLake,
1212
isAtlas as checkIsAtlas,
1313
isLocalAtlas as checkIsLocalAtlas,
@@ -122,6 +122,7 @@ export async function getInstance(
122122
getParameterResult,
123123
atlasVersionResult,
124124
isLocalAtlas,
125+
genuineMongoDB,
125126
] = await Promise.all([
126127
runCommand(
127128
adminDb,
@@ -158,6 +159,7 @@ export async function getInstance(
158159
return await client.db(db).collection(collection).countDocuments(query);
159160
}
160161
),
162+
buildGenuineMongoDBInfo(uri, client),
161163
]);
162164

163165
const isAtlas = !!atlasVersionResult.atlasVersion || checkIsAtlas(uri);
@@ -166,8 +168,8 @@ export async function getInstance(
166168
auth: adaptAuthInfo(connectionStatus),
167169
build: adaptBuildInfo(buildInfoResult),
168170
host: adaptHostInfo(hostInfoResult),
169-
genuineMongoDB: buildGenuineMongoDBInfo(uri),
170171
dataLake: buildDataLakeInfo(buildInfoResult),
172+
genuineMongoDB,
171173
featureCompatibilityVersion:
172174
getParameterResult?.featureCompatibilityVersion.version ?? null,
173175
isAtlas,
@@ -196,8 +198,24 @@ export function configuredKMSProviders(
196198
.map(([kmsProviderName]) => kmsProviderName as any);
197199
}
198200

199-
function buildGenuineMongoDBInfo(uri: string): GenuineMongoDBDetails {
200-
const { isGenuine, serverName } = getGenuineMongoDB(uri);
201+
async function buildGenuineMongoDBInfo(
202+
uri: string,
203+
client: MongoClient
204+
): Promise<GenuineMongoDBDetails> {
205+
const adminDb = client.db('admin');
206+
const serverName = await identifyServerName({
207+
connectionString: uri,
208+
async adminCommand(doc) {
209+
try {
210+
const result = await adminDb.command(doc);
211+
debug('adminCommand(%O) = %O', doc, result);
212+
return result;
213+
} catch (err) {
214+
debug('adminCommand(%O) failed %O', doc, err);
215+
throw err;
216+
}
217+
},
218+
});
201219

202220
return {
203221
isGenuine: serverName === 'mongodb',

0 commit comments

Comments
 (0)