From f040afed48d22b28f36908129e90061fe3b68a9a Mon Sep 17 00:00:00 2001 From: Daniel Augusto de Melo Santos Date: Tue, 21 May 2019 14:50:24 -0300 Subject: [PATCH] Fixing bin script for NPX --- README.md | 77 ++++++++++++++++++++++++++-------------------------- bin/run.sh | 2 ++ package.json | 4 +-- src/index.js | 20 ++++++++++++-- 4 files changed, 59 insertions(+), 44 deletions(-) create mode 100755 bin/run.sh diff --git a/README.md b/README.md index 726ca5a..0fc77db 100644 --- a/README.md +++ b/README.md @@ -12,47 +12,11 @@ Do not update the secrets by AWS Console it is prone to errors! This tool automatically adds to the .gitignore an .secrets to avoid pushing the folder to GIT -## Setup -```sh -npm install -``` - -## CLI Options - --f, --fetch-secrets - -Operation to fetch the secrets - -The "AWSCURRENT" version is downloaded and stored at ` .secrets/current.json` - - --u, --update-secrets - -Operation to update the secrets - -A local backup is stored at `.secrets/.json`. The contents of `.secrets/current.json` are then uploaded to AWS. - --r, --region [value] - -Parameter to set AWS Region, it is optional and defaults to us-east-1 - --n, --secret-name [value] - -The secret name on Secrets Manager - --p, --secret-path [value] - -The secret file path containing the value of the secrets, this is required when using update - --v --verbose - -The log is output in debug mode, with more information +## Usage --i --secret-version-id [value] +You must have NodeJS 8 or superior installed on your machine. -The secret version id, use list to show possible values, when using rollback this is required - -## Usage +The commands are: Fetching secrets @@ -96,3 +60,38 @@ Check the CreatedDate and with the VersionId in hands, you can do the rollback w ```bash npx reliquary --rollback-secrets -n -i 5617687a-763b-4301-bb23-bda7dd49c3fe ``` + +## CLI Options + +-f, --fetch-secrets + +Operation to fetch the secrets + +The "AWSCURRENT" version is downloaded and stored at ` .secrets/current.json` + + +-u, --update-secrets + +Operation to update the secrets + +A local backup is stored at `.secrets/.json`. The contents of `.secrets/current.json` are then uploaded to AWS. + +-r, --region [value] + +Parameter to set AWS Region, it is optional and defaults to us-east-1 + +-n, --secret-name [value] + +The secret name on Secrets Manager + +-p, --secret-path [value] + +The secret file path containing the value of the secrets, this is required when using update + +-v --verbose + +The log is output in debug mode, with more information + +-i --secret-version-id [value] + +The secret version id, use list to show possible values, when using rollback this is required diff --git a/bin/run.sh b/bin/run.sh new file mode 100755 index 0000000..33dcc91 --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +node ./src/index.js $@ diff --git a/package.json b/package.json index eccac0d..879f0c7 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "reliquary", - "version": "1.0.1", + "version": "1.0.2", "description": "An project for managing secrets", "main": "src/index.js", - "bin": "./src/index.js", + "bin": "./bin/run.sh", "scripts": { "test": "jest --coverage --config=jest.config.js test/", "lint": "eslint src/", diff --git a/src/index.js b/src/index.js index a204fe5..1be9748 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ const { fetch } = require('./fetcher'); const { update } = require('./updater'); const { listVersions } = require('./listVersions'); const { rollback } = require('./rollback'); -const { transportsDefinition } = require('./logger'); +const { transportsDefinition, logger } = require('./logger'); program .option('-f, --fetch-secrets', 'Operation to fetch the secrets') @@ -19,8 +19,21 @@ program .option('-v, --verbose', 'Output the log in debug mode') .parse(process.argv); +// two here means it is only the node command and the index.js file, without parameters +if (!program.rawArgs.length || program.rawArgs.length === 2) { + program.help(); + process.exit(); +} + +if (!program.fetchSecrets && !program.updateSecrets && !program.listSecrets + && !program.rollbackSecrets) { + logger.error('An operation is required: fetch, list, update or rollback'); + process.exit(); +} + if (!program.secretName) { - throw new Error('Secret Name is necessary, pass it on with -n command parameter'); + logger.error('Secret Name is necessary, pass it on with -n command parameter'); + process.exit(); } if (program.verbose) { @@ -31,7 +44,8 @@ if (program.fetchSecrets) { fetch(program.secretName, program.region); } else if (program.updateSecrets) { if (!program.secretPath) { - throw new Error('The path to the secret file is necessary'); + logger.error('The path to the secret file is necessary'); + process.exit(); } const secretContent = fs.readFileSync(program.secretPath, 'utf-8');