Git Product home page Git Product logo

nodecredstash's Introduction

nodecredstash

Build Status Coverage Status npm version dependencies

Node.js port of credstash

=============

$ npm install --save nodecredstash
let Credstash = require('nodecredstash');

let credstash = new Credstash({table: 'credential-store', awsOpts: {region: 'us-west-2'}});

credstash.putSecret({name: 'Death Star vulnerability', secret: 'Exhaust vent', version: 1, context: {rebel: 'true'}})
  .then(() => credstash.getSecret({name: 'Death Star vulnerability', version: 1, context: {rebel: 'true'}})
  .then(secret => console.log(secret));

Options

table

The DynamoDB table to store credentials default: credential-store

kmsKey

The name of the KMS key created for credstash. default: alias/credstash

awsOpts

Options to be passed to the aws-sdk instance for DynamoDB and KMS Specifig configurations can be found for DynamoDB and KMS. region can be sent in as a parameter, or you can follow other AWS conventions for setting the region ex:

{
  "region": "us-east-1"
}

Options that are specific to the DynamoDB configuration. Defaults can still be assigned in awsOpts, but they can be overridden just for dynamoDb here

Options that are specific to the KMS configuration. Defaults can still be assigned in awsOpts, but they can be overridden just for kms here

Function arguments

name

The name of the secret that will be stored in DynamoDB

Can be a string or number. If it is a number, then nodecredstash will pad it with 0s so it can be sorted.

Used to get the encryption key from KMS.

cb

An optional callback function when you don't want to use promises;

credstash.getSecret({
      name: 'Death Star plans',
      context: {rebelShip: 'true'}
    }, function(err, res) {
    if (err) {
      throw new Error('The Death Star plans are not in the main computer.');
    }
    ...
})

Functions

.createDdbTable([cb])

Create the table in DynamoDB using the table option

.putSecret({name, secret, [version], [context]}, [cb])

Encode a secret and place it in DynamoDB.

credstash.putSecret({name: 'Death Star Vulnerability', secret: 'Exhaust vent', context: { rebel: 'true'}});

DynamoDB will now contain a record for this entry that looks like:

{
  "name": "Death Star Vulnerability", //
  "key": "...", // The value sent to KMS to retrieve the decryption key
  "version": "0000000000000000001", // The version string, should be sorteable
  "hmac": "...", // An HMAC validation value
  "contents": "..." // The AES 128 encrypted value
}

getHighestVersion({name}, [cb])

Returns the first sorted result for the given name key.

incrementVersion({name}, [cb])

Returns the next incremented version version for the given name key.

.getSecret({name, [version], [context]}, [cb])

Retrieve a decrypted secret from DynamoDB.

credstash.getSecret({name: 'Death Star Vulnerability', context: {rebelDroid: 'true'}})
  .then(secrets => console.log(JSON.stringify(secrets, null, 2)));
{
  "Death Star Vulnerability": "Exhaust vent"
}

.getAllSecrets({[version], [context]}, [cb])

Retrieve all decrypted secrets from DynamoDB.

credstash.getAllSecrets({context: {rebel: 'true'}})
  .then(secrets => console.log(JSON.stringify(secrets, null, 2)));
{
  "Death Star vulnerability": "Exhaust vent"
}

.getAllVersions({name, [limit]}, [cb])

Retrieve all or the last N(limit) versions of a secret.

credstash.getAllSecrets({name: 'Death Star vulnerability', limit: 2, context: {rebel: 'true'}})
  .then(secrets => console.log(JSON.stringify(secrets, null, 2)));
[ { "version": "0000000000000000006", "secret": "Exhaust vent" },
  { "version": "0000000000000000005", "secret": "Destroy vent" } ]

.listSecrets([cb])

Retrieve all stored secrets and their highest version

credstash.listSecrets()
  .then(list => console.log(JSON.stringify(list, null, 2)));
[
  {
    "name": "Death Star",
    "version": "0000000000000000001"
  },
  {
    "name": "Death Star vulnerability",
    "version": "0000000000000000001"
  }
]

.deleteSecret({name, version}, [cb])

Delete the desired secret by version from DynamoDB

credstash.deleteSecret({name: 'Death Star', version: 1})
// 'Deleting Death Star -- version 0000000000000000001'
  .then(() => credstash.list())
  .then(list => console.log(JSON.stringify(list, null, 2));
[
  {
    "name": "Death Star vulnerability",
    "version": "0000000000000000001"
  }
]

.deleteSecrets(name)

Deletes all of the versions of name

credstash.deleteSecrets({name: 'Death Star vulnerability'})
// 'Deleting Death Star vulnerability -- version 0000000000000000001'
  .then(() => credstash.listSecrets())
  .then(list => console.log(JSON.stringify(list, null, 2));
[]

nodecredstash's People

Contributors

davidtanner avatar stephan-nordnes-eriksen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.