-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from NitorCreations/node-cli
Add Node.js CLI
- Loading branch information
Showing
8 changed files
with
237 additions
and
1,106 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@nitor/aws-vault-cli", | ||
"version": "0.0.1", | ||
"description": "Command-line interface for AWS vault", | ||
"author": { | ||
"name": "Nitor", | ||
"email": "", | ||
"url": "http://nitor.com" | ||
}, | ||
"contributors": [ | ||
"Eetu Huisman <[email protected]>" | ||
], | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/NitorCreations/vault" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/NitorCreations/vault/issues" | ||
}, | ||
"license": "Apache-2.0", | ||
"peerDependencies": { | ||
"@nitor/aws-vault": "0.1.1" | ||
}, | ||
"dependencies": { | ||
"sade": "^1.4.2" | ||
} | ||
} |
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,64 @@ | ||
#!/usr/bin/env node | ||
const sade = require('sade'); | ||
const loadOptions = require('../lib/loadOptions'); | ||
const client = require('../lib/vaultClient'); | ||
|
||
const DEFAULT_STACK_NAME = 'vault'; | ||
|
||
const handleRejection = err => { | ||
console.error(err); | ||
process.exit(1); | ||
}; | ||
|
||
const prog = sade('vault'); | ||
|
||
prog.option('--vaultstack', 'Optional CloudFormation stack to lookup key and bucket.', DEFAULT_STACK_NAME); | ||
prog.option('-p, --prefix', 'Optional prefix to store values under. Empty by default'); | ||
prog.option('-b, --bucket', 'Override the bucket name either for initialization or storing and looking up values'); | ||
prog.option('-k, --key-arn', 'Override the KMS key arn for storing or looking up values'); | ||
prog.option('--id', 'Give an IAM access key id to override those defined by the environment'); | ||
prog.option('--secret', 'Give an IAM secret access key to override those defined by the environment'); | ||
prog.option('-r, --region', 'Give a region for the stack and the bucket'); | ||
|
||
prog | ||
.command('store <name> <value>') | ||
.describe('Store data in the vault') | ||
.option('-w, --overwrite', 'Overwrite the current value if it already exists', false) | ||
.action((name, value, options) => { | ||
loadOptions(options) | ||
.then(options => client.store(name, value, options)) | ||
.catch(handleRejection); | ||
}) | ||
.command('lookup <name>') | ||
.describe('Look up data from the vault') | ||
.action((name, options) => { | ||
loadOptions(options) | ||
.then(options => client.lookup(name, options)) | ||
.then(console.log) | ||
.catch(handleRejection); | ||
}) | ||
.command('delete <name>') | ||
.describe('Delete data from the vault') | ||
.action((name, options) => { | ||
loadOptions(options) | ||
.then(options => client.delete(name, options)) | ||
.catch(handleRejection) | ||
}) | ||
.command('exists <name>') | ||
.describe('Check if the vault contains data') | ||
.action((name, options) => { | ||
loadOptions(options) | ||
.then(options => client.exists(name, options)) | ||
.then(console.log) | ||
.catch(handleRejection) | ||
}) | ||
.command('all') | ||
.describe('List all keys the vault contains') | ||
.action(options => { | ||
loadOptions(options) | ||
.then(options => client.all(options)) | ||
.then(console.log) | ||
.catch(handleRejection) | ||
}); | ||
|
||
prog.parse(process.argv); |
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,15 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
mri@^1.1.0: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a" | ||
integrity sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w== | ||
|
||
sade@^1.4.2: | ||
version "1.6.1" | ||
resolved "https://registry.yarnpkg.com/sade/-/sade-1.6.1.tgz#aba16655e998b2b68beb9f13938af010f42eddd2" | ||
integrity sha512-USHm9quYNmJwFwhOnEuJohdnBhUOKV1mhL0koHSJMLJaesRX0nuDuzbWmtUBbUmXkwTalLtUBzDlEnU940BiQA== | ||
dependencies: | ||
mri "^1.1.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const awscred = require('awscred'); | ||
const { promisify } = require('util'); | ||
const { CloudFormation } = require('aws-sdk'); | ||
|
||
const loadCredentialsAndRegion = promisify(awscred.loadCredentialsAndRegion); | ||
|
||
module.exports = (options) => loadCredentialsAndRegion() | ||
.then(({ region }) => new CloudFormation({ region }).describeStacks({ StackName: options.vaultstack }).promise() | ||
.then((describeStackOutput) => Promise.resolve({ describeStackOutput, region }))) | ||
.then(({ describeStackOutput, region }) => { | ||
const stack = describeStackOutput.Stacks[0]; | ||
return Promise.resolve({ | ||
vaultKey: options.k || stack.Outputs.find(output => output.OutputKey === 'kmsKeyArn').OutputValue, | ||
bucketName: options.b || stack.Outputs.find(output => output.OutputKey === 'vaultBucketName').OutputValue, | ||
region, | ||
}); | ||
}); |
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
Oops, something went wrong.