awsssm

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

README

Build Status codecov Go Report Card GoDoc

go-aws-ssm

Go package that interfaces with AWS System Manager.

Why to use go-aws-ssm and not the aws-sdk-go?

This package is wrapping the aws-sdk-go and hides the complexity dealing with the not so Go friendly AWS SDK. Perfect use case for this package is when secure parameters for an application are stored to AWS Parameter Store using a path hierarchy. During application startup you can use this package to fetch them and use them in your application.

Install

go get github.com/Jamil-Najafov/go-aws-ssm

Examples

Basic Usage
        //Assuming you have the parameters in the following format:
    	//my-service/dev/param-1  -> with value `a`
    	//my-service/dev/param-2  -> with value `b`
    	pmstore, err := awsssm.NewParameterStore()
    	if err != nil {
    		return err
    	}
    	//Requesting the base path
    	params, err := pmstore.GetAllParametersByPath("/my-service/dev/", true)
    	if err!=nil{
    		return err
    	}
    	
    	//And getting a specific value
    	value:=params.GetValueByName("param-1")
    	//value should be `a`
    	
    	
Integrates easily with viper
        //Assuming you have the parameters in the following format:
     	//my-service/dev/param-1  -> with value `a`
     	//my-service/dev/param-2  -> with value `b`
     	pmstore, err := awsssm.NewParameterStore()
     	if err != nil {
     		return err
     	}
     	//Requesting the base path
     	params, err := pmstore.GetAllParametersByPath("/my-service/dev/", true)
     	if err!=nil{
     		return err
     	}
    
    	//Configure viper to handle it as json document, nothing special here!
    	v := viper.New()
    	v.SetConfigType(`json`)
    	//params object implements the io.Reader interface that is required
    	err = v.ReadConfig(params)
    	if err != nil {
    		return err
    	}
    	value := v.Get(`param-1`)
    	//value should be `a`

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrParameterNotFound error for when the requested Parameter Store parameter can't be found
	ErrParameterNotFound = errors.New("parameter not found")
	//ErrParameterInvalidName error for invalid parameter name
	ErrParameterInvalidName = errors.New("invalid parameter name")
)

Functions

This section is empty.

Types

type Parameter

type Parameter struct {
	Value *string
}

Parameter holds a Systems Manager parameter from AWS Parameter Store

func (*Parameter) GetValue

func (p *Parameter) GetValue() string

GetValue return the actual Value of the parameter

type ParameterStore

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

ParameterStore holds all the methods tha are supported against AWS Parameter Store

func NewParameterStore

func NewParameterStore(ssmConfig ...*aws.Config) (*ParameterStore, error)

NewParameterStore is creating a new ParameterStore by creating an AWS Session

func NewParameterStoreWithClient

func NewParameterStoreWithClient(client ssmClient) *ParameterStore

NewParameterStoreWithClient is creating a new ParameterStore with the given ssm Client

func (*ParameterStore) GetAllParametersByPath

func (ps *ParameterStore) GetAllParametersByPath(path string, decrypt bool) (*Parameters, error)

GetAllParametersByPath is returning all the Parameters that are hierarchy linked to this path For example a request with path as /my-service/dev/ Will return /my-service/dev/param-a, /my-service/dev/param-b, etc... but will not return recursive paths the `ssm:GetAllParametersByPath` permission is required to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/*`

This will also page through and return all elements in the hierarchy, non-recursively

func (*ParameterStore) GetParameter

func (ps *ParameterStore) GetParameter(name string, decrypted bool) (*Parameter, error)

GetParameter is returning the parameter with the given name For example a request with name as /my-service/dev/param-1 Will return the parameter value if exists or ErrParameterInvalidName if parameter cannot be found The `ssm:GetParameter` permission is required to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource

func (*ParameterStore) PutSecureParameter

func (ps *ParameterStore) PutSecureParameter(name, value string, overwrite bool) error

PutSecureParameter is setting the parameter with the given name to a passed in value. Allow overwriting the value of the parameter already exists, otherwise an error is returned For example a request with name as '/my-service/dev/param-1': Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty and `overwrite` is false. The `ssm:PutParameter` permission is required to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource

func (*ParameterStore) PutSecureParameterWithCMK

func (ps *ParameterStore) PutSecureParameterWithCMK(name, value string, overwrite bool, kmsID string) error

PutSecureParameterWithCMK is the same as PutSecureParameter but with a passed in CMK (Customer Master Key) For example a request with name as '/my-service/dev/param-1' and a `kmsID` of 'foo': Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty and `overwrite` is false. The `ssm:PutParameter` permission is required to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource The `kms:Encrypt` permission is required to the `arn:aws:kms:us-east-1:710015040892:key/foo`

type Parameters

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

Parameters holds the output and all AWS Parameter Store that have the same base path

func NewParameters

func NewParameters(basePath string, parameters map[string]*Parameter) *Parameters

NewParameters creates a Parameters

func (*Parameters) Decode

func (p *Parameters) Decode(output interface{}) error

Decode decodes the parameters into the given struct We are using this package to decode the values to the struct https://github.com/mitchellh/mapstructure For more details how you can use this check the parameter_test.go file

func (*Parameters) GetAllValues

func (p *Parameters) GetAllValues() map[string]string

GetAllValues returns a map with all the keys and values in the store.

func (*Parameters) GetValueByFullPath

func (p *Parameters) GetValueByFullPath(name string) string

GetValueByFullPath returns the value based on the full path

func (*Parameters) GetValueByName

func (p *Parameters) GetValueByName(name string) string

GetValueByName returns the value based on the name so the AWS Parameter Store parameter name is base path + name

func (*Parameters) Read

func (p *Parameters) Read(des []byte) (n int, err error)

Read implements the io.Reader interface for the key/value pair

Jump to

Keyboard shortcuts

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