Skip to content

Commit 091d8f5

Browse files
committed
chore: add helper to detect digital ocean MONGOSH-860
1 parent fc4a738 commit 091d8f5

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Returns a boolean.
4747
### isLocalhost(uri)
4848
Returns a boolean.
4949

50+
### isDigitalOcean(uri)
51+
Returns a boolean.
52+
5053
### getGenuineMongoDB(buildInfo, cmdLineOpts)
5154
Returns an object:
5255

index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ export declare function getDataLake(buildInfo: any): {
44
};
55

66
export declare function isEnterprise(buildInfo: any): boolean;
7-
export declare function isAtlas(buildInfo: any): boolean;
8-
export declare function isLocalhost(buildInfo: any): boolean;
7+
export declare function isAtlas(uri: string): boolean;
8+
export declare function isLocalhost(uri: string): boolean;
9+
export declare function isDigitalOcean(uri: string): boolean;
910

1011
export declare function getGenuineMongoDB(buildInfo: any, cmdLineOpts: any): {
1112
isGenuine: boolean;

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const ATLAS_REGEX = /mongodb.net[:/]/i;
1+
const ATLAS_REGEX = /mongodb\.net[:/]/i;
22
const LOCALHOST_REGEX = /(localhost|127\.0\.0\.1)/i;
3+
const DIGITAL_OCEAN_REGEX = /\.mongo\.ondigitalocean\.com[:/]/i;
34

45
function getDataLake(buildInfo) {
56
const res = {
@@ -35,6 +36,10 @@ function isLocalhost(uri) {
3536
return !!uri.match(LOCALHOST_REGEX);
3637
}
3738

39+
function isDigitalOcean(uri) {
40+
return !!uri.match(DIGITAL_OCEAN_REGEX);
41+
}
42+
3843
function getBuildEnv(buildInfo) {
3944
const serverOs = buildInfo.buildEnvironment ?
4045
buildInfo.buildEnvironment.target_os : null;
@@ -68,4 +73,4 @@ function getGenuineMongoDB(buildInfo, cmdLineOpts) {
6873
return res;
6974
}
7075

71-
module.exports = { getDataLake, isEnterprise, isAtlas, isLocalhost, getGenuineMongoDB, getBuildEnv };
76+
module.exports = { getDataLake, isEnterprise, isAtlas, isLocalhost, isDigitalOcean, getGenuineMongoDB, getBuildEnv };

test/index.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fixtures = require('./fixtures');
33
const isAtlas = require('../.').isAtlas;
44
const getDataLake = require('../.').getDataLake;
55
const isLocalhost = require('../.').isLocalhost;
6+
const isDigitalOcean = require('../.').isDigitalOcean;
67
const getBuildEnv = require('../.').getBuildEnv;
78
const isEnterprise = require('../.').isEnterprise;
89
const getGenuineMongoDB = require('../.').getGenuineMongoDB;
@@ -62,6 +63,12 @@ describe('mongodb-build-info', () => {
6263
});
6364
});
6465

66+
context('isDigitalOcean', () => {
67+
it('reports on digital ocean', () => {
68+
expect(isDigitalOcean('mongodb+srv://admin:[email protected]/test?authSource=admin&replicaSet=dave')).to.be.true;
69+
});
70+
});
71+
6572
context('isGenuineMongoDB', () => {
6673
it('reports on CosmosDB', () => {
6774
const isGenuine = getGenuineMongoDB(fixtures.COSMOSDB_BUILD_INFO, fixtures.CMD_LINE_OPTS);

0 commit comments

Comments
 (0)