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-cdk-generator

v1.0.5

Published

This is a CDK generator that takes the go github.com/mariotoffia/ssm.git Report and produces CDK objects

Downloads

18

Readme

Introduction

This package generates CDK classes, using templates, from the go ssm report.

Reporting

It is possible to generate a report as object and JSON using the golang ssm report. This may be used in a DevOps pipeline to e.g. use CDK to create Parameter Store & Secrets Manager entities to be provisioned using cloud formation. Hence it is possible to have default values by passing the struct as value instead of nil pointer with a specific interface type.

For example, the following

type Sample struct {
  ConnectionString string `asm:"connectstring, strkey=password, gurka=biffen, nasse=hunden"`
  Secret string `asm:"mysecret"`
  Parameter string `pms:"parameter, description=A sample value, pattern=.*, my=hobby, by=test"`
}

set := Sample{
  ConnectString: "{\"user\":\"nisse\"}",
  Secret: "{\"private\": \"nobody knows\", \"lockkey\":\"eeej1¤¤&1!\"}",
  Parameter: "a parameter"
}

s := NewSsmSerializer("dev", "test-service")
objs, json, err := s.ReportWithOpts(&set, NoFilter, true)
if err != nil {
  panic(err)
}

Renders a JSON report on the following format:

{
  "parameters": [
    {
      "type": "secrets-manager",
      "fqname": "/dev/test-service/connectstring",
      "keyid": "",
      "description": "",
      "tags": {"gurka":"biffen","nasse":"hunden"},
      "details": {
        "strkey": "password"
      },
      "value": "{\"user\": \"nisse\"}"      
    },
    {
      "type": "secrets-manager",
      "fqname": "/dev/test-service/mysecret",
      "keyid": "",
      "description": "",
      "tags": {},
      "details": {
        "strkey": null
      },
      "value": "{\"private\": \"nobody knows\", \"lockkey\":\"eeej1¤¤&1!\"}"      
    },
    {
      "type": "parameter-store",
      "fqname": "/dev/test-service/parameter",
      "keyid": "",
      "description": "A sample value",
      "tags": {"my":"hobby", "by": "test"},
      "details": {
        "pattern": ".*",
        "tier": "Standard"
      },
      "value": "a parameter",
      "valuetype": "String"
    }                
  ]
}

However since it returns a Report object containing Parameters you may do your own JSON or otherwise generation from the Report object. It is also possible to use filter to filter out fields in same manner as Marshal and Unmarshal works.

From this JSON it is possible to transform it to e.g. CDK @aws-cdk/aws-ssm object such as

new ssm.StringParameter(stack, 'Parameter', {
  allowedPattern: '.*',
  description: 'The value Foo',
  parameterName: 'FooParameter',
  stringValue: 'Foo',
  tier: ssm.ParameterTier.ADVANCED,
});

CDK Generator

This is an implementation of a CDK generator, that is template driven to fit your CDK generation needs.For example given the report JSON file above and use ssm-cdk-generator will output the following using default templates.

import * as cdk from '@aws-cdk/core';
    import * as asm from '@aws-cdk/aws-secretsmanager';
    import * as pms from '@aws-cdk/aws-ssm';

    export class SsmParamsConstruct extends cdk.Construct {
      constructor(scope: cdk.Construct, id: string) {
        super(scope, id);

        // SetupSecrets & SetupParameters must be named exactly as stated below!
        this.SetupSecrets();
        this.SetupParameters();
      }

      private SetupSecrets() {
              new asm.CfnSecret(this, 'Secret0', {
                description: '',
                name: '/dev/test-service/connectstring',
                generateSecretString: {
                  secretStringTemplate: '{"user": "nisse"}',
                  generateStringKey: 'password',
                },
                tags: [{"key":"gurka","value":"biffen"},{"key":"nasse","value":"hunden"}]
              });
              new asm.CfnSecret(this, 'Secret1', {
                description: '',
                name: '/dev/test-service/mysecret',
                secretString: '{"private": "nobody knows", "lockkey":"eeej1¤¤&1!"}',
                tags: []
              });

      }

      private SetupParameters() {
          new pms.CfnParameter(this, 'Parameter0', {
                name: '/dev/test-service/parameter',
                type: 'String',
                value: 'a parameter',
                allowedPattern: '.*',
                description: 'A sample value',
                policies: ''
                tags: {"my":"hobby","by":"test"},
                tier: 'Standard'
              });
      }
    }

Use the node app/index.js --help to get help on which parameters you may use.

Options:
  --help           Show help                                           [boolean]
  --version        Show version number                                 [boolean]
  --outfile, -o    An optional outfile to write the resulting CDK Construct
  --stdout         Output the result onto stdout. This may be combined with
                   --outfile
  --infile, -i     The ssm report file to read from filesystem instead of
                   default stdin
  --tsconfig       Optional tsconfig.json file to use when generating the source
                   code
  --clsname, -c    Optional a class name for the generated CDK class
  --tmplasm, --ta  Optional a template fqfilepath that shall be used for asm
                   parameter
  --tmplpms, --tp  Optional a template fq filepath that shall be used for
                   generating pms parameter
  --tmplclz, --tc  Optional a template fq filepath that shall be used for
                   generating a new file / class

Templates are very simple and the default resides under the _ssm-cdk-generator/templates for reviewing. For example a template to generate a single Parameter Store Parameter could look like this.

new pms.CfnParameter(this, 'Parameter{index}', {
      name: '{fqname}',
      type: '{valuetype}',
      value: '{value}',
      allowedPattern: '{details.pattern}',
      description: '{description}',
      policies: '{policies}'
      tags: {tags},
      tier: '{details.tier}'
    });