ez-aws-secrets
v1.0.9
Published
This package is a easy implementation to gather AWS secrets. It uses the AWS sdk and provides typings for typescript development also.
Downloads
6
Maintainers
Readme
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
*/