npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ac-awssecrets

v2.1.0

Published

Reads secrets from AWS secrets manager and adds them to the configuration of the embedding app.

Downloads

17

Readme

AC AWS Secrets

Reads secrets from AWS secrets manager and adds them to the configuration of the embedding app.

example workflow

Version 2 - BREAKING CHANGES

  • works with Node16 or higher
  • async/await - no callback!
  • uses AWS IAM roles or AWS IAM profiles instead of IAM credentials

Parameters

|Parameter|Type|Required|Description| |---|---|---|---| |key|string|yes|the local variable name| |name|string|yes|the name of the AWS secret| |servers|bool|-|See below |valueHasJSON|bool|-|If true, some properties have JSON content (prefixed with JSON:)

Usage

AWS secret is a JSON object. Those properties will be merged with local config properties based on the secret's name.

Secret

Store secret in AWS

Example secret
// name: mySecret1
{
  prop1: 'abc',
  prop2: 123,
  prop3: 'JSON:{"jprop1": "abc}'
}

Configure a local variable, that should be enhanced with the secret

const config = {
  key1: {},
  otherKey: {
    prop10: 'https://www.admiralcloud.com'
  }
}

Fetch secrets

const secrets = [
  { key: 'key1', name: 'mySecret1' } // key is the config var, name is the AWS secret name
]
await awsSecrets.loadSecrets({ secrets, config })

// config will change  - key1 will be enhanced with AWS secret
const config = {
  key1: {
    prop1: 'abc',
    prop2: 123,
    prop3: 'JSON:{"jprop1": "abc}'
  },
  otherKey: {
    prop10: 'https://www.admiralcloud.com'
  }
}

Multisecrets

Use multisecrets if you want to add a number of additional secrets to be fetched. Usually it is used to fetch multiple objects for an array of objects:

Store multisecret in AWS

Example secret
// name: mySecret2
{
  values: '["aws.key1", "aws.key2"]'
}

Store secrets in AWS

// name: aws.key1
{
  accessKeyId: 'awsKey1',
  secretAccessKey: 'awsSecret1'
}

// name: aws.key2
{
  accessKeyId: 'awsKey2',
  secretAccessKey: 'awsSecret2'
}

Configure a local variable, that should be enhanced with the secret

const config = {
  mySecret2: [],
  otherKey: {
    prop10: 'https://www.admiralcloud.com'
  }
}

Fetch secrets

const multisecrets = [
  { key: 'mySecret2', name: 'mySecret2' } // key is the config var, name is the AWS secret name
]
const secrets = []
await awsSecrets.loadSecrets({ secrets, multisecrets, config })

// config will change  - key1 will be enhanced with AWS secret
const config = {
  mySecret2: [
    {
      accessKeyId: 'awsKey1',
      secretAccessKey: 'awsSecret1'
    },
    {
      accessKeyId: 'awsKey2',
      secretAccessKey: 'awsSecret2'
    }
  ]
}

VERSION 1 - OUTDATED

Usage

Simple example

Lets assume we have the following configuration and secret

let existingConfig = {
  redis: {
    host: 'localhost'
  }
}

// Stored under name "redis.cacheServer" in AWS
let secret = {
  host: 'my-secret-server'
}

The following setup will replace the existing configuration and redis.host will be "my-secret-server"

const secretParams = {
  aws: {
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    region: 'eu-central-1'
  },
  secrets: [
    { key: 'redis', name: 'redis.cacheServer', ignoreInTestMode: true }
  ],
  config: existingConfig,
  environment: 'development'
}

awsSecrets.loadSecrets(secretParams, (err, result) => {
  if (err) return cb(err)
  _.forEach(result, (item) => {
    console.log('Setting secret for', _.padEnd(_.get(item, 'key'), 25), '->', _.get(item, 'name'))
  })
  return cb()
})

Example with array of objects

let existingConfig = {
  redis: {
    databases: [
      { db: 0, name: 'cache' },
      { db: 1, name: 'auth' }
    ]
  }
}

// secret stored under "redis.cacheServer"
let secret = {
  host: 'my-secret-server'

// secert storend under "redis.authServer"
let secret = {
  host: 'my-auth-server
}

// now use the function
const secretParams = {
  aws: {
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    region: 'eu-central-1'
  },
  secrets: [
    { key: 'redis.databases', name: 'redis.cacheServer', servers: { identifier: 'name', value: 'cache' } }
    { key: 'redis.databases', name: 'redis.authServer', servers: { identifier: 'name', value: 'auth' } }
  ],
  config: existingConfig,
  environment: 'development'
}

awsSecrets.loadSecrets(secretParams, (err, result) => {
  // now 
  redis.databases: [
    { db: 0, name: 'cache', host: 'my-secret-server' },
    { db: 1, name: 'auth', host: 'my-auth-server' }
  ]
})

Links

License

MIT License Copyright © 2009-present, AdmiralCloud AG, Mark Poepping