@znemz/aws-play
Advanced tools
Comparing version 0.0.1 to 0.0.2
const yargs = require('yargs'); | ||
const getArgs = () => { | ||
const { argv } = yargs.option('encoding', { | ||
alias: 'e', | ||
type: 'string', | ||
description: `incoming or outgoing additional encoding / decoding | ||
const { argv } = yargs | ||
.option('encoding', { | ||
alias: 'e', | ||
type: 'string', | ||
description: `incoming or outgoing additional encoding / decoding | ||
IE: | ||
@@ -12,4 +13,15 @@ - encrypt -> will take the decimal outpu and encode in base64 | ||
`, | ||
choices: ['base64', 'hex', 'binary'], | ||
}); | ||
choices: ['base64', 'hex', 'binary'], | ||
}) | ||
.option('key-id', { | ||
alias: 'k', | ||
type: 'string', | ||
description: 'aws kms id or alias defaults to proccess.env.KMS_ID', | ||
}) | ||
.option('forceKeyId', { | ||
alias: 'fk', | ||
type: 'bool', | ||
description: | ||
'for decrypt which defaults to false IE uses first key that works, this is to foce a specific key usage', | ||
}); | ||
@@ -16,0 +28,0 @@ return argv; |
@@ -20,15 +20,20 @@ #!/usr/bin/env node | ||
text = decoder(String(text)); | ||
kms.decrypt( | ||
{ | ||
CiphertextBlob: text, | ||
}, | ||
(err, data) => { | ||
if (err) { | ||
cb(err); | ||
} | ||
cb(null, data.Plaintext); | ||
const opts = { CiphertextBlob: text }; | ||
if (args.forceKeyId) { | ||
const kmsId = args['key-id'] || process.env.KMS_ID; | ||
if (kmsId) { | ||
opts.KeyId = kmsId; | ||
} | ||
); | ||
} | ||
kms.decrypt(opts, (err, data) => { | ||
if (err) { | ||
cb(err); | ||
} | ||
cb(null, data.Plaintext); | ||
}); | ||
}); | ||
process.stdin.pipe(decrypt).pipe(process.stdout); |
@@ -18,3 +18,3 @@ #!/usr/bin/env node | ||
{ | ||
KeyId: process.env.KMS_ID, | ||
KeyId: args['key-id'] || process.env.KMS_ID, | ||
Plaintext: text, | ||
@@ -21,0 +21,0 @@ }, |
{ | ||
"name": "@znemz/aws-play", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
5613
8
145
14
3