Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Returns a boolean.
### isLocalhost(uri)
Returns a boolean.

### isDigitalOcean(uri)
Returns a boolean.

### getGenuineMongoDB(buildInfo, cmdLineOpts)
Returns an object:

Expand Down
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export declare function getDataLake(buildInfo: any): {
};

export declare function isEnterprise(buildInfo: any): boolean;
export declare function isAtlas(buildInfo: any): boolean;
export declare function isLocalhost(buildInfo: any): boolean;
export declare function isAtlas(uri: string): boolean;
export declare function isLocalhost(uri: string): boolean;
export declare function isDigitalOcean(uri: string): boolean;

export declare function getGenuineMongoDB(buildInfo: any, cmdLineOpts: any): {
isGenuine: boolean;
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ATLAS_REGEX = /mongodb.net[:/]/i;
const ATLAS_REGEX = /mongodb\.net[:/]/i;
const LOCALHOST_REGEX = /(localhost|127\.0\.0\.1)/i;
const DIGITAL_OCEAN_REGEX = /\.mongo\.ondigitalocean\.com[:/]/i;

function getDataLake(buildInfo) {
const res = {
Expand Down Expand Up @@ -35,6 +36,10 @@ function isLocalhost(uri) {
return !!uri.match(LOCALHOST_REGEX);
}

function isDigitalOcean(uri) {
return !!uri.match(DIGITAL_OCEAN_REGEX);
}

function getBuildEnv(buildInfo) {
const serverOs = buildInfo.buildEnvironment ?
buildInfo.buildEnvironment.target_os : null;
Expand Down Expand Up @@ -68,4 +73,4 @@ function getGenuineMongoDB(buildInfo, cmdLineOpts) {
return res;
}

module.exports = { getDataLake, isEnterprise, isAtlas, isLocalhost, getGenuineMongoDB, getBuildEnv };
module.exports = { getDataLake, isEnterprise, isAtlas, isLocalhost, isDigitalOcean, getGenuineMongoDB, getBuildEnv };
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fixtures = require('./fixtures');
const isAtlas = require('../.').isAtlas;
const getDataLake = require('../.').getDataLake;
const isLocalhost = require('../.').isLocalhost;
const isDigitalOcean = require('../.').isDigitalOcean;
const getBuildEnv = require('../.').getBuildEnv;
const isEnterprise = require('../.').isEnterprise;
const getGenuineMongoDB = require('../.').getGenuineMongoDB;
Expand Down Expand Up @@ -62,6 +63,12 @@ describe('mongodb-build-info', () => {
});
});

context('isDigitalOcean', () => {
it('reports on digital ocean', () => {
expect(isDigitalOcean('mongodb+srv://admin:[email protected]/test?authSource=admin&replicaSet=dave')).to.be.true;
});
});

context('isGenuineMongoDB', () => {
it('reports on CosmosDB', () => {
const isGenuine = getGenuineMongoDB(fixtures.COSMOSDB_BUILD_INFO, fixtures.CMD_LINE_OPTS);
Expand Down