-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
640 additions
and
31 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
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,42 @@ | ||
const rp = require('request-promise'); | ||
|
||
|
||
function updateMasks(secret) { | ||
const port = process.env.PORT || 8080; | ||
const host = process.env.HOST || 'localhost'; | ||
|
||
const opt = { | ||
uri: `http://${host}:${port}/secrets`, | ||
method: 'POST', | ||
json: true, | ||
body: secret, | ||
resolveWithFullResponse: true, | ||
}; | ||
|
||
rp(opt) | ||
.then((res) => { | ||
if (res.statusCode >= 400) { | ||
console.log(`could not create mask for secret: ${secret.key}, because server responded with: ${res.statusCode}\n\n${res.body}`); | ||
process.exit(1); | ||
} | ||
console.log(`successfully updated masks with secret: ${secret.key}`); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.log(`could not create mask for secret: ${secret.key}, due to error: ${err}`); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
if (require.main === module) { | ||
// first argument is the secret key second argument is the secret value | ||
if (process.argv.length < 4) { | ||
console.log('not enough arguments, need secret key and secret value'); | ||
process.exit(2); | ||
} | ||
const key = process.argv[2]; | ||
const value = process.argv[3]; | ||
updateMasks({ key, value }); | ||
} else { | ||
module.exports = updateMasks; | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
version: 1.3.0 | ||
version: 1.4.0 |
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,78 @@ | ||
/* jshint ignore:start */ | ||
|
||
'use strict'; | ||
const Q = require('q'); | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
const proxyquire = require('proxyquire').noCallThru(); | ||
chai.use(sinonChai); | ||
|
||
const originalProcessExit = process.exit; | ||
|
||
describe('addNewMask', () => { | ||
before(() => { | ||
process.exit = sinon.spy(); | ||
}); | ||
|
||
beforeEach(() => { | ||
process.exit.resetHistory(); | ||
}); | ||
|
||
after(() => { | ||
process.exit = originalProcessExit; | ||
}); | ||
|
||
describe('positive', () => { | ||
it('should send a request to add a secret', async () => { | ||
const rpSpy = sinon.spy(() => Q.resolve({ statusCode: 201 })); | ||
const addNewMask = proxyquire('../lib/addNewMask', { | ||
'request-promise': rpSpy | ||
}); | ||
|
||
process.env.PORT = 1337; | ||
process.env.HOST = '127.0.0.1'; | ||
|
||
const secret = { | ||
key: '123', | ||
value: 'ABC', | ||
}; | ||
|
||
addNewMask(secret); | ||
|
||
expect(rpSpy).to.have.been.calledOnceWith({ | ||
uri: `http://127.0.0.1:1337/secrets`, | ||
method: 'POST', | ||
json: true, | ||
body: secret, | ||
resolveWithFullResponse: true, | ||
}); | ||
await Q.delay(10); | ||
expect(process.exit).to.have.been.calledOnceWith(0); | ||
}); | ||
}); | ||
|
||
describe('negative', () => { | ||
it('should send a request to add a secret', async () => { | ||
const rpSpy = sinon.spy(() => Q.reject('could not send request')); | ||
const addNewMask = proxyquire('../lib/addNewMask', { | ||
'request-promise': rpSpy | ||
}); | ||
|
||
process.env.PORT = 1337; | ||
process.env.HOST = '127.0.0.1'; | ||
|
||
const secret = { | ||
key: '123', | ||
value: 'ABC', | ||
}; | ||
|
||
addNewMask(secret); | ||
await Q.delay(10); | ||
expect(process.exit).to.have.been.calledOnceWith(1); | ||
}); | ||
}); | ||
}); | ||
|
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
Oops, something went wrong.