1.1.0 • Published 1 year ago

@dvsa/secrets-manager v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Secrets Manager

A utility class for accessing secrets stored with AWS Secrets Manager.

Provides ability to override keys by implementing them as ENVIRONMENT variables.

Configuration

Accessing the AWS Secrets Manager requires these environment variables:

AWS_REGION

The AWS region, normally this is supplied by default within AWS resources.

This is used by the AWS Secrets Manager Client.

Example

eu-west-1

Using the utility class

The class SecretsManager provides two methods:

getSecret(secretName)

async getSecret(secretName: string): Promise<Record<string, string>> {}

This method will return a KEY, VALUE pairs as an object of all secrets stored in the AWS Secrets Manager store specified by secretName. This store contains KEY, VALUE pairs.

getSecretWithKey(secretName, key)

async getSecretWithKey(secretName: string, key: string): Promise<string> {}

This method will call the previous, and extract (if defined) the key-value from the secret store.

Overriding key values

Should you need to override the value from key you can specify the key as an environment variable. A call will not be made to AWS Secrets Manager. This makes it useful for local development environments.

Example
console.log(process.env.MY_KEY_NAME); //MySecret

const secret = getSecretWithKey('mySecretName', 'MY_KEY_NAME');

console.log(secret); // MySecret

Requirements

Build

  • npm i
  • npm run build:dev

Tests

  • The Jest framework is used to run tests and collect code coverage
  • To run the tests, run the following command within the root directory of the project: npm test
  • Coverage results will be displayed on terminal and stored in the coverage directory
    • The coverage requirements can be set in jest.config.js

Logging

This library uses https://github.com/debug-js/debug to provide an opt-in logging experience.

To enable logging from this package, set the DEBUG environment variable to @dvsa/secrets-manager. For example, to run your tests with the library in debug logging mode:s

DEBUG=@dvsa/secrets-manager npm run test