Skip to content

Commit a107245

Browse files
committed
add getBuildEnv function to extract server arch and os
1 parent e06787c commit a107245

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Returns an object:
5353
__isGenuine__: boolean.
5454
__serverName__: name of the server (mongoDB, cosmosDB, or documentDB).
5555

56+
### getBuildEnv(buildInfo)
57+
Returns an object:
58+
59+
__serverOs__: build's OS version (macOS, linux, windows etc.).
60+
__serverArch__: build's architecture (e.g. x86_64).
61+
5662
# Installation
5763
```
5864
npm install -S mongodb-build-info

index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ function isLocalhost(uri) {
3535
return !!uri.match(LOCALHOST_REGEX);
3636
}
3737

38+
function getBuildEnv(buildInfo) {
39+
const serverOs = buildInfo.buildEnvironment ?
40+
buildInfo.buildEnvironment.target_os : null;
41+
const serverArch = buildInfo.buildEnvironment ?
42+
buildInfo.buildEnvironment.target_arch : null;
43+
44+
return { serverOs, serverArch };
45+
}
46+
3847
function getGenuineMongoDB(buildInfo, cmdLineOpts) {
3948
const res = {
4049
isGenuine: true,
@@ -59,4 +68,4 @@ function getGenuineMongoDB(buildInfo, cmdLineOpts) {
5968
return res;
6069
}
6170

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

test/index.spec.js

Lines changed: 9 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 getBuildEnv = require('../.').getBuildEnv;
67
const isEnterprise = require('../.').isEnterprise;
78
const getGenuineMongoDB = require('../.').getGenuineMongoDB;
89

@@ -37,6 +38,14 @@ describe('mongodb-build-info', () => {
3738
});
3839
});
3940

41+
context('getBuildEnv', () => {
42+
it('returns server os and server arch', () => {
43+
const buildEnv = getBuildEnv(fixtures.BUILD_INFO_3_2);
44+
expect(buildEnv.serverOs).to.equal('osx');
45+
expect(buildEnv.serverArch).to.equal('x86_64');
46+
});
47+
});
48+
4049
context('isAtlas', () => {
4150
it('reports on atlas', () => {
4251
expect(isAtlas('mongodb+srv://admin:[email protected]/admin')).to.be.true;

0 commit comments

Comments
 (0)