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

ssm-get-jsonified

v1.2.6

Published

This library is capable of reading any given hierachical path in AWS SSM and outputing it as a single json schema.

Downloads

26

Readme

Build Status Coverage Status

Table of Contents

Problem

AWS System Manager's Parameter Store has the capability of storing parameters in a hierachical manner.

Refer: https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html

e.g

    $ aws ssm put-parameter --name /myApp/prod/dbConfig/password --value complexPasswprd --type SecureString
    $ aws ssm put-parameter --name /myApp/prod/dbConfig/url --value dbUrl --type String
    $ aws ssm put-parameter --name /myApp/prod/salesforce/loginUrl --value sfLoginUrl --type String
    $ aws ssm put-parameter --name /myApp/prod/salesforce/username --value sfLoginUserName --type String
    $ aws ssm put-parameter --name /myApp/prod/salesforce/password --value sfLoginPassword --type SecureString
    $ aws ssm put-parameter --name /myApp/prod/salesforce/sso/redirectUrl --value sfSSORedirectUrl --type SecureString
    $ admins-MacBook-Pro:ssm-get-jsonified dahamp$ 

By stroing as in above, parameters can be retrieved for any given path onwards.

e.g To get database configs

    $ aws ssm get-parameters-by-path --path /myApp/prod/dbConfig/ --recursive --with-decryption

Output:

    {
        "Parameters": [
            {
                "Name": "/myApp/prod/dbConfig/password",
                "Type": "SecureString",
                "Value": "complexPasswprd",
                "Version": 1,
                "LastModifiedDate": 1558252777.295,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/dbConfig/password"
            },
            {
                "Name": "/myApp/prod/dbConfig/url",
                "Type": "String",
                "Value": "dbUrl",
                "Version": 1,
                "LastModifiedDate": 1558252814.22,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/dbConfig/url"
            },
            {
                "Name": "/myApp/prod/dbConfig/username",
                "Type": "String",
                "Value": "myDBUser",
                "Version": 1,
                "LastModifiedDate": 1558252684.218,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/dbConfig/username"
            }
         ]
    }

e.g To get salesforce configs

    $ aws ssm get-parameters-by-path --path /myApp/prod/salesforce/  --recursive --with-decryption

Output:

    {
        "Parameters": [
            {
                "Name": "/myApp/prod/salesforce/loginUrl",
                "Type": "String",
                "Value": "sfLoginUrl",
                "Version": 1,
                "LastModifiedDate": 1558252855.452,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/salesforce/loginUrl"
            },
            {
                "Name": "/myApp/prod/salesforce/password",
                "Type": "SecureString",
                "Value": "sfLoginPassword",
                "Version": 1,
                "LastModifiedDate": 1558252912.342,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/salesforce/password"
            },
            {
                "Name": "/myApp/prod/salesforce/sso/entityId",
                "Type": "SecureString",
                "Value": "sfSSOEntityId",
                "Version": 1,
                "LastModifiedDate": 1558253003.0,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/salesforce/sso/entityId"
            },
            {
                "Name": "/myApp/prod/salesforce/sso/redirectUrl",
                "Type": "SecureString",
                "Value": "sfSSORedirectUrl",
                "Version": 1,
                "LastModifiedDate": 1558252969.846,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/salesforce/sso/redirectUrl"
            },
            {
                "Name": "/myApp/prod/salesforce/username",
                "Type": "String",
                "Value": "sfLoginUserName",
                "Version": 1,
                "LastModifiedDate": 1558252882.669,
                "ARN": "arn:aws:ssm:us-west-2:429869777392:parameter/myApp/prod/salesforce/username"
            }
        ]
    }

However, this is cumbersome for an application stores its configurations which have considerable amount of parameters in each of them following complex hierachical structures.

ssm-get-jsonified can retrieve configurations for a given path prefix in JSON format while preserving it's hierachical structure.

Installation

To install the stable version:

    $ npm install ssm-get-jsonified

Setting AWS Credentials

Set credentials in the AWS credentials profile file on your local system, located at:

~/.aws/credentials on Linux, macOS, or Unix

C:\Users\USERNAME\.aws\credentials on Windows

This file should contain lines in the following format:

[default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key

Substitute your own AWS credentials values for the values your_access_key_id and your_secret_access_key.

Usage

Fetch Configurations Asynchronously

To get database configurations in /myApp/prod/dbConfigs

Using Callbacks

    const ssmJsonified = require('ssm-get-jsonified');

    ssmJsonified.ssmGetJsonifiedAsync('us-west-2', '/myApp/prod/dbConfig', function(configuration) {
      
        // Logic to process required configuration

        // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "password": "complexPasswprd",
         *       "url": "dbUrl",
         *       "username": "myDBUser"
         *   }
         * 
         *  */ 
    });

Using Promises

ssmJsonified.ssmGetJsonifiedAsync('us-west-2', '/myApp/prod/salesforce')
    .then(configuration => {
        // Logic to process required configuration

        // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "password": "complexPasswprd",
         *       "url": "dbUrl",
         *       "username": "myDBUser"
         *   }
         * 
         *  */ 
    })
    .catch((err) => {
        
    })

To get database configurations in /myApp/prod/salesforce

Using Callbacks

    const ssmJsonified = require('ssm-get-jsonified');

    ssmJsonified.ssmGetJsonifiedAsync('us-west-2', '/myApp/prod/salesforce', function(configuration) {
      
        // Logic to process required configuration

        // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "loginUrl": "sfLoginUrl",
         *       "password": "sfLoginPassword",
         *       "sso": {
         *                "entityId": *"sfSSOEntityId",
         *                "redirectUrl": *"sfSSORedirectUrl"
         *               },
         *       "username": "sfLoginUserName"
         *   }
         *  */ 
    });

Using Promises

ssmJsonified.ssmGetJsonifiedAsync('us-west-2', '/myApp/prod/salesforce')
    .then(configuration => {
         // Logic to process required configuration

        // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "loginUrl": "sfLoginUrl",
         *       "password": "sfLoginPassword",
         *       "sso": {
         *                "entityId": *"sfSSOEntityId",
         *                "redirectUrl": *"sfSSORedirectUrl"
         *               },
         *       "username": "sfLoginUserName"
         *   }
         *  */ 
    })
    .catch((err) => {
        
    })

Fetch Configurations Synchronously

Note: Executing synchronously is not reccommended as it blocks the call back loop expliciltly.

To get database configurations in /myApp/prod/dbConfigs

let configuration = ssmJsonified.ssmGetJsonifiedSync('us-west-2', '/myApp/prod/salesforce')

  // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "password": "complexPasswprd",
         *       "url": "dbUrl",
         *       "username": "myDBUser"
         *   }
         * 
         *  */ 

To get database configurations in /myApp/prod/salesforce

let configuration = ssmJsonified.ssmGetJsonifiedSync('us-west-2', '/myApp/prod/salesforce')

 // configuration - configurations in path prefix onwards.
        /**
         * {
         *       "loginUrl": "sfLoginUrl",
         *       "password": "sfLoginPassword",
         *       "sso": {
         *                "entityId": *"sfSSOEntityId",
         *                "redirectUrl": *"sfSSORedirectUrl"
         *               },
         *       "username": "sfLoginUserName"
         *   }
         *  */ 

License

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.