1.0.9 • Published 4 years ago

ez-aws-secrets v1.0.9

Weekly downloads
9
License
ISC
Repository
-
Last release
4 years ago

Easy AWS Secrets

This package is a easy implementation to gather AWS secrets. It uses the AWS sdk and provides typings for typescript development also.

Installation

Simply intall via npm:

npm install ez-aws-secrets

Usage

There a two functionalities provided by this package

1. get

A simple function to get one or more aws secrets.

Inputs:

  • endpoint: string - Your AWS endpoint
  • region: string - Your AWS region
  • secrets: string [] - Array of secret ID's to retrieve

Outputs:

  • If given a single element in the array, the function returns the secret value
  • If given multiple, an object mapping secret id to value is returned

Example 1:

const { get } = require('ez-aws-secrets');
const endpoint = '...';
const region = '...';
const secretNames = ['testSecret'];

const value = get(endpoint, region, secretNames);
// Returned: secret value

Example 2:

const { get } = require('ez-aws-secrets');
const endpoint = '...';
const region = '...';
const secretNames = ['testSecret', 'testSecret2'];

const value = get(endpoint, region, secretNames);
/* Returned:
{
    'testSecret': value
    'testSecret2': value
}
*/

2. SecretManager

The SecretManager class allows a bulk of secrets to be retrieved upon initialisation, stored/cached and re-gathered efficiently later.

class SecretManager {
  // A public array mapping the secretID to the value
  public secrets: { secretID: any };

  /**
   * Initialises the class with the endpoint and region
   *
   *  @param { string } endpoint - AWS Endpoint
   *  @param { string } region - AWS Region
   */
  constructor(enpoint: string, region: string) {}

  /**
   * Function to initialise a bulk of secret keys. These
   * are stored in the secrets object.
   *
   *  @param { string[] } secrets - Array of secret IDs
   *
   *  @returns { "secretID": any } - Object mapping secretID to secret value for all secrets
   */
  async init(secrets: string[]) {}

  /**
   * Retrieves a secret value from the secrets object if exists, else retreives
   * from secret manager.
   *
   * @param {string} secret - SecretID to retrieve
   *
   * @returns { any } The secret value
   */
  async getSecret(secret: string) {}
}

Example:

const { SecretManager } = require('ez-aws-secrets');
const endpoint = '...';
const region = '...';
const secretNames = ['testSecret', 'testSecret2'];

const manager = new SecretManager(endpoint, region);
const values = await manager.init(secretNames);
/* Returned:
{
    'testSecret': value
    'testSecret2': value
}
*/

const secret = await manager.getSecret('testSecret');
/* Returned:
Secret Value
*/
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago