Skip to content

Commit

Permalink
make keys explicitly included to prevent leaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanley Stuart committed Nov 3, 2014
1 parent 30af6dd commit c885731
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DOTENV_VAR="dotenv"
DO_NOT_ALLOW="this should not show up in ENV"
6 changes: 5 additions & 1 deletion Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

var app = new EmberAddon();
var app = new EmberAddon({
dotEnv: {
allow: ['DOTENV_VAR']
}
});

// Use `app.import` to add additional libraries to the generated
// output files.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ file in the root of your repository:
DROPBOX_KEY=YOURKEYGOESHERE
```

Next, put some configuration in your Brocfile. Starting in 0.2.0, *keys must be explicitly allowed*:

```javascript
// Brocfile.js

var app = new EmberApp({
dotEnv: {
allow: ['DROPBOX_KEY']
}
});

// pre-generated config from ember-cli
module.exports = app.toTree();
```

then, you can access the environment variables anywhere in your app like
you usually would.

Expand Down
19 changes: 16 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ module.exports = {
var path = require('path');
var fs = require('fs');
var dotenv = require('dotenv');
var app = this.app;
var project = this.project;
var loadedConfig;
var config = {};
var allowedKeys = (app.options.dotEnv && app.options.dotEnv.allow) || [];

var configFilePath = path.join(this.project.root, '.env');
console.log('allowedKeys', allowedKeys);

var configFilePath = path.join(project.root, '.env');

if (fs.existsSync(configFilePath)){
return dotenv.parse(fs.readFileSync(configFilePath));
loadedConfig = dotenv.parse(fs.readFileSync(configFilePath));
} else {
return {};
loadedConfig = {};
}

allowedKeys.forEach(function(key){
config[key] = loadedConfig[key];
});

return config;
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-dotenv",
"version": "0.1.1",
"version": "0.2.0",
"directories": {
"doc": "doc",
"test": "tests"
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ module("smoke test");
test("should work", function(){
equal(ENV.DOTENV_VAR, "dotenv");
});

test("doesn't put in keys unless they are explicitly allowed", function(){
equal(Object.hasOwnProperty.call(ENV, 'DO_NOT_ALLOW'), false);
});

0 comments on commit c885731

Please sign in to comment.