ssmwrap

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 10 Imported by: 8

README

ssmwrap

Documentation

ssmwrap execute commands with output values loaded from AWS SSM Parameter Store to somewhere.

Supported output targets:

  • environment variables

Usage

$ ssmwrap -paths /production -- your_command

Install

Download binary from releases

or

$ brew tap handlename/homebrew-tap
$ brew install ssmwrap

or

$ go get github.com/handlename/ssmwrap/cmd/ssmwrap

Options

$ ssmwrap -help
Usage of ./cmd/ssmwrap/ssmwrap:
  -env
    	export values as environment variables (default true)
  -env-entire-path
    	use entire parameter path for name of environment variables
    	disabled: /path/to/value -> VALUE
    	enabled: /path/to/value -> PATH_TO_VALUE
  -env-prefix string
    	prefix for environment variables
  -file value
    	write values as file
    	format:  Name=VALUE_NAME,Path=FILE_PATH,Mode=FILE_MODE,Gid=FILE_GROUP_ID,Uid=FILE_USER_ID
    	example: Name=/foo/bar,Path=/etc/bar,Mode=600,Gid=123,Uid=456
  -names string
    	comma separated parameter names
  -no-env
    	disable export to environment variables
  -no-recursive
    	retrieve values just under -paths only
  -paths string
    	comma separated parameter paths
  -prefix string
    	alias for -env-prefix
  -recursive
    	retrieve values recursively (default true)
  -retries int
    	number of times of retry
  -version
    	display version
Environment Variables

All of command line options can be set via environment variables.

$ SSMWRAP_PATHS=/production ssmwrap ...

means,

$ ssmwrap -paths /production ...

If there are command line options too, these takes priority.

$ SSMWRAP_PREFIX=FOO_ ssmwrap -prefix BAR_ env
BAR_SOMETHING=...

Motivation

There are some tools to use values stored in AWS System Manager Parameter Store, but I couldn't find that manipulate values including newline characters correctly.

ssmwrap runs your command through syscall.Exec, not via shell, so newline characters are treated as part of a environment value.

Usage as a library

ssmwrap.Export() fetches parameters from SSM and export those to envrionment variables.

err := ssmwrap.Export(ssmwrap.ExportOptions{
	Paths: []string{"/path/"},
	Retries: 3,
	Prefix: "SSM_",
})
if err != nil {
	// ...
}
foo := os.Getenv("SSM_FOO")  // a value of /path/foo in SSM

License

see LICENSE file.

Special Thanks

@fujiwara has gave me an idea of ssmwrap.

Author

@handlename (https://github.com/handlename)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export

func Export(options ExportOptions) error

Export fetches paramters from SSM and export those to environment variables. This is for use ssmwrap as a library.

func Run

func Run(options RunOptions, ssm SSMConnector, dests []Destination) error

Types

type DefaultSSMConnector

type DefaultSSMConnector struct{}

type Destination

type Destination interface {
	Name() string
	Output(parameters map[string]string) error
}

type DestinationEnv

type DestinationEnv struct {
	Prefix        string
	UseEntirePath bool
}

DestinationEnv is an implementation of Destination interface.

func (DestinationEnv) Name

func (d DestinationEnv) Name() string

func (DestinationEnv) Output

func (d DestinationEnv) Output(parameters map[string]string) error

type DestinationFile

type DestinationFile struct {
	Targets []FileTarget
}

DestinationFile is an implementation of Destination interface.

func (DestinationFile) Name

func (d DestinationFile) Name() string

func (DestinationFile) Output

func (d DestinationFile) Output(parameters map[string]string) error

type ExportOptions

type ExportOptions struct {
	Paths         []string
	Names         []string
	Prefix        string
	UseEntirePath bool
	Recursive     bool
	Retries       int
}

type FileTarget

type FileTarget struct {
	Name string
	Path string
	Mode os.FileMode
	Uid  int
	Gid  int
}

func (FileTarget) IsSatisfied

func (t FileTarget) IsSatisfied() error

func (FileTarget) String

func (t FileTarget) String() string

type RunOptions

type RunOptions struct {
	// Paths is target paths on SSM Parameter Store.
	// If there are multiple paths, all of related values will be loaded.
	Paths []string

	// Names are names on SSM Parameter Store.
	Names []string

	// Recursive tell ssmwrap to retrieve values from SSM recursively.
	Recursive bool

	// Retry limit to request to SSM.
	Retries int

	// Command and arguments to run.
	Command []string
}

type SSMConnector

type SSMConnector interface {
	// contains filtered or unexported methods
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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