ssmcache

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2021 License: MIT Imports: 8 Imported by: 0

README

ssmcache

Cache un/encrypted expiring values as AWS SSM parameters with a TTL

Usage

Docs

import (
    "github.com/CribAdvisor/ssmcache"
)

func main() {
    cache := ssmcache.New(&ssmcache.SSMCacheOptions{
        Secret: true,
        BasePath: "/cache",
        KeyId: nil,
    })

    accessToken, err := cache.Get("my_token")
    if err != nil {
        panic(err)
    }
    if token == nil {
        // obtain a new token
        // newToken, ttl := getNewToken(...)
        accessToken = newToken
        cache.Set("my_token", accessToken, ttl)
    }
}

Required IAM permissions

NOTE:

  1. Replace Resource with your AWS region and account ID
  2. Replace /cache with the modified BasePath if applicable
  3. Add kms:Encrypt and kms:Decrypt actions and resources for your KMS key (if applicable)
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1585412677747",
      "Action": [
        "ssm:DeleteParameter",
        "ssm:GetParameter",
        "ssm:PutParameter"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:ssm:<region>:<account_ID>:parameter/cache/*"
    }
  ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSMCache added in v0.3.0

type SSMCache struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, options *SSMCacheOptions) (*SSMCache, error)

New creates a new cache, if options are nil, the defaults are used

Defaults: Secret=true BasePath="/cache" KeyId=nil

func (*SSMCache) Get added in v0.3.0

func (cache *SSMCache) Get(ctx context.Context, key string) (*string, error)

Get retrieves a parameter from SSM with the given key, excluding the BasePath of the cache

func (*SSMCache) Set added in v0.3.0

func (cache *SSMCache) Set(ctx context.Context, key string, value string, ttl time.Duration) error

Set puts a parameter into SSM for the given key, excluding the BasePath of the cache

type SSMCacheOptions

type SSMCacheOptions struct {
	// Secret is used to set SSM parameter type, true for SecureString, false for String
	Secret *bool

	// BasePath is where the parameters are stored within SSM, excluding trailing slash
	//
	// Be sure to update the IAM policy (see README.md) to match this
	BasePath *string

	// KeyId is the ARN of KMS key id to use to encrypt parameter value
	KeyId *string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL