Skip to content

Commit cfa0e31

Browse files
committed
Add a new identifyServerName function
1 parent fe26c42 commit cfa0e31

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/mongodb-build-info/src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import ConnectionString from 'mongodb-connection-string-url';
22

3+
type Document = Record<string, unknown>;
4+
35
const ATLAS_REGEX = /\.mongodb(-dev|-qa|-stage)?\.net$/i;
46
const ATLAS_STREAM_REGEX = /^atlas-stream-.+/i;
57
const LOCALHOST_REGEX =
@@ -134,6 +136,28 @@ export function getGenuineMongoDB(uri: string): {
134136
};
135137
}
136138

139+
export async function identifyServerName(
140+
uri: string,
141+
runCommand: (command: Document) => Promise<Document>,
142+
): Promise<string> {
143+
const hostname = getHostnameFromUrl(uri);
144+
if (hostname.match(COSMOS_DB_REGEX)) {
145+
return 'cosmosdb';
146+
}
147+
148+
if (hostname.match(DOCUMENT_DB_REGEX)) {
149+
return 'documentdb';
150+
}
151+
152+
const buildInfo = await runCommand({ buildInfo: 1 });
153+
154+
if ('ferretdb' in buildInfo) {
155+
return 'ferretdb';
156+
}
157+
158+
return 'mongodb';
159+
}
160+
137161
export function getBuildEnv(buildInfo: unknown): {
138162
serverOs: string | null;
139163
serverArch: string | null;

0 commit comments

Comments
 (0)