Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to load key from env variable #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/keySources/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2017 Tom Shawver
*/

'use strict'

module.exports = () => {
return new Promise((resolve, reject) => {
if (process.env.CRYPTEX_ENV_KEY) {
resolve(process.env.CRYPTEX_ENV_KEY)
} else {
reject(new Error('CRYPTEX_ENV_KEY not assigned'))
}
})
}
22 changes: 22 additions & 0 deletions test/src/keySources/env.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017 Tom Shawver
*/

'use strict'

const getKey = require('src/keySources/env')

describe('Environment Source', () => {
it('resolves with the provided key', () => {
process.env.CRYPTEX_ENV_KEY = 'bar'

return getKey().then((key) => {
should.exist(key)
key.should.equal('bar')
})
})
it('rejects when option "key" is missing', () => {
delete process.env.CRYPTEX_ENV_KEY
return getKey().should.be.rejected
})
})