File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
packages/mongodb-build-info/src Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11import ConnectionString from 'mongodb-connection-string-url' ;
22
3+ type Document = Record < string , unknown > ;
4+
35const ATLAS_REGEX = / \. m o n g o d b ( - d e v | - q a | - s t a g e ) ? \. n e t $ / i;
46const ATLAS_STREAM_REGEX = / ^ a t l a s - s t r e a m - .+ / i;
57const 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+
137161export function getBuildEnv ( buildInfo : unknown ) : {
138162 serverOs : string | null ;
139163 serverArch : string | null ;
You can’t perform that action at this time.
0 commit comments