aboutsummaryrefslogtreecommitdiff
path: root/store/store.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2022-11-21 00:00:55 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2022-11-21 00:01:06 -0500
commit35f9d0a511653604764dd8a033ac9cba00248443 (patch)
tree9fc3d12a4d7a48abb1a25aefbb0a36181534e4a9 /store/store.go
parent15f0d12bf1475b5c77121abd2c0f6d0a06791dc2 (diff)
downloaddpw-ssm-master.tar.gz
dpw-ssm-master.tar.xz
Update the docs, mild reorgHEADmaster
Diffstat (limited to 'store/store.go')
-rw-r--r--store/store.go37
1 files changed, 29 insertions, 8 deletions
diff --git a/store/store.go b/store/store.go
index fc42193..ece4040 100644
--- a/store/store.go
+++ b/store/store.go
@@ -1,3 +1,9 @@
+// Store is not designed to be used as a database, or some high intensity
+// key/value store, rather a low volume ad-hoc key value store for secrets
+// inside of AWS.
+//
+// This should work out of the box with pretty much every AWS account.
+// See also the bundled program.
package store
import (
@@ -11,24 +17,30 @@ import (
"github.com/aws/aws-sdk-go/service/ssm"
)
-const SSM_MAX_SIZE = 4096
+const SSM_MAX_SIZE = 4096 // This is dictated by AWS
-// ((16^4)*4096)/1024/1024
-// If we ever need more than 256 MB in parameter store, we've done something
-// very wrong.
-const SSM_KEY_FORMAT = "%s-%04X" //
+const SSM_KEY_FORMAT = "%s-%04X" // Should be good up to 256MB ( 16^4 bytes... )
var (
// TrimRegex is used to group the SSM keys inside of the Info struct under
- // ByKey. This will only be used for params that exceed 4KB.
+ // ByKey. This is used so that we can have keys larger than 4KB.
+ // See also SSM_KEY_FORMAT
TrimRegex = regexp.MustCompile("-[0-9A-E][0-9A-E][0-9A-E][0-9A-E]$")
- // Optional, can be set set to utilize a specific KMS key if desired.
+ // KMS_KEY_ID is optional, can be set set to utilize a specific KMS key if
+ // desired.
KMS_KEY_ID *string = nil
+ // Tags are also optional, if used with the bundled program you can
+ // simply set an environment variable. Otherwise, set them here
+ // at the package level.
Tags = []*ssm.Tag{}
)
+// Info contains a few maps with pointers to all of the parameters, setup with
+// different keys for easy lookup. `ByKey` is what you'd expect. `ByFullKey`
+// has a dash and four hex digits appended to it for entries larger than 4K
+// and actually reflects the keys you'll see in the parameter store console.
type Info struct {
ByKey map[string]*Entry
ByFullKey map[string]*Entry
@@ -65,12 +77,14 @@ func (i *Info) add(e *ssm.ParameterMetadata) {
i.ByFullKey[*e.Name] = entry
}
+// Entry represents an entry in the store, and all of the actual parameters
+// that it spans
type Entry struct {
Name string
Keys []*ssm.ParameterMetadata
}
-// GetInfo returns a populated Info struct from the SSM
+// GetInfo returns a populated Info struct from the parameter store.
func GetInfo(svc *ssm.SSM) (*Info, error) {
ret := &Info{
ByKey: map[string]*Entry{},
@@ -97,6 +111,8 @@ func GetInfo(svc *ssm.SSM) (*Info, error) {
return ret, nil
}
+// InsertParam will chuck data from the rdr into the parameter store under
+// key, automatically chunking it into multiple parameters as needed.
func InsertParam(svc *ssm.SSM, rdr io.Reader, key string) error {
buf := &bytes.Buffer{}
enc := base64.NewEncoder(base64.StdEncoding, buf)
@@ -144,6 +160,9 @@ func InsertParam(svc *ssm.SSM, rdr io.Reader, key string) error {
return nil
}
+// GetParam will suck data out of parameter store for a key, automatically
+// collecting all of the individual parameters needed to reconstruct the data
+// and writes it out to the io.Writer
func GetParam(svc *ssm.SSM, wrtr io.Writer, key string) error {
n := 1
buf := &bytes.Buffer{}
@@ -178,6 +197,8 @@ func GetParam(svc *ssm.SSM, wrtr io.Writer, key string) error {
return nil
}
+// RemoveParam takes care of collecting all of the pieces for a given key,
+// and removes all of them from the parameter store
func RemoveParam(svc *ssm.SSM, key string) error {
info, err := GetInfo(svc)
if err != nil {