Skip to content

Commit

Permalink
Fixing bin script for NPX
Browse files Browse the repository at this point in the history
  • Loading branch information
dmelosantos committed May 21, 2019
1 parent b4a2081 commit f040afe
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 44 deletions.
77 changes: 38 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<secret-version-id>.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

Expand Down Expand Up @@ -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 <secret-name> -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/<secret-version-id>.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
2 changes: 2 additions & 0 deletions bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
node ./src/index.js $@
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
20 changes: 17 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand All @@ -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');

Expand Down

0 comments on commit f040afe

Please sign in to comment.