This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
138 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
node_modules/* | ||
api/.DS_Store | ||
manifest* | ||
npm-debug.log | ||
.DS_Store | ||
cf-ssh.yml | ||
coverage/* | ||
public/bower_components/* | ||
public/bower_components/* | ||
credentials*.json | ||
docker-compose.override.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var _defaults = require('lodash.defaults'); | ||
var _get = require('lodash.get'); | ||
|
||
var defaults = { | ||
GITHUB_CLIENT_ID: null, | ||
GITHUB_CLIENT_SECRET: null, | ||
GITHUB_ORG: null, | ||
SESSION_SECRET: null, | ||
MONGODB_URI: 'mongodb://localhost:27017/checklistomania' | ||
}; | ||
|
||
function load(_fromEnv) { | ||
var env = {}; | ||
var credentials; | ||
var vcapServices; | ||
var fromEnv = _fromEnv; | ||
|
||
if (!fromEnv) { | ||
fromEnv = process.env; | ||
} | ||
|
||
if (fromEnv.VCAP_SERVICES) { | ||
vcapServices = JSON.parse(fromEnv.VCAP_SERVICES); | ||
|
||
credentials = _get(vcapServices, 'user-provided[0].credentials'); | ||
|
||
if (credentials) { | ||
_defaults(env, | ||
credentials, | ||
{ MONGODB_URI: _get(vcapServices, 'mongodb26-swarm[0].credentials.uri') }); | ||
} | ||
} else { | ||
_defaults(env, fromEnv, defaults); | ||
} | ||
|
||
return env; | ||
} | ||
|
||
module.exports = { load: load }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
applications: | ||
- name: checklistomania-dev | ||
instances: 1 | ||
memory: 512M | ||
disk_quota: 1024M | ||
routes: | ||
- route: checklistomania-dev.app.cloud.gov | ||
services: | ||
- checklistomania-mongodb | ||
- checklistomania-env | ||
stack: cflinuxfs2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* global describe it expect */ | ||
var env = require('../../lib/env'); | ||
|
||
function makeVcapServicesEnv(vcapServices) { | ||
return { | ||
VCAP_SERVICES: JSON.stringify(vcapServices) | ||
}; | ||
} | ||
|
||
describe('env properly loads config values', function () { | ||
it('has default MONGODB_URI', function (done) { | ||
var e = env.load({}); | ||
expect(e.MONGODB_URI).toBe('mongodb://localhost:27017/checklistomania'); | ||
done(); | ||
}); | ||
|
||
it('defaults other required values to null', function (done) { | ||
var e = env.load({}); | ||
expect(e.GITHUB_CLIENT_ID).toBeNull(); | ||
expect(e.GITHUB_CLIENT_SECRET).toBeNull(); | ||
expect(e.GITHUB_ORG).toBeNull(); | ||
expect(e.SESSION_SECRET).toBeNull(); | ||
done(); | ||
}); | ||
|
||
it('loads from the specified env', function (done) { | ||
var e = env.load({ | ||
SOME_ENV_VAR: 'whatever' | ||
}); | ||
expect(e.SOME_ENV_VAR).toBe('whatever'); | ||
done(); | ||
}); | ||
|
||
it('loads from process.env by default', function (done) { | ||
var e; | ||
process.env = { | ||
ENV_VAR_IN_PROCESS_ENV: 'whatever' | ||
}; | ||
e = env.load(); | ||
expect(e.ENV_VAR_IN_PROCESS_ENV).toBe('whatever'); | ||
done(); | ||
}); | ||
|
||
it('loads from VCAP_SERVICES', function (done) { | ||
var e = env.load(makeVcapServicesEnv({ | ||
'user-provided': [{ | ||
credentials: { | ||
GITHUB_CLIENT_ID: 'clientId', | ||
GITHUB_CLIENT_SECRET: 'clientSecret', | ||
GITHUB_ORG: 'org', | ||
SESSION_SECRET: 'sessionSecret' | ||
} | ||
}], | ||
'mongodb26-swarm': [{ | ||
credentials: { | ||
uri: 'mongodb://whatever' | ||
} | ||
}] | ||
})); | ||
expect(e.GITHUB_CLIENT_ID).toBe('clientId'); | ||
expect(e.GITHUB_CLIENT_SECRET).toBe('clientSecret'); | ||
expect(e.GITHUB_ORG).toBe('org'); | ||
expect(e.SESSION_SECRET).toBe('sessionSecret'); | ||
expect(e.MONGODB_URI).toBe('mongodb://whatever'); | ||
done(); | ||
}); | ||
}); |