diff --git a/cmd/run.go b/cmd/run.go index e181182..1b8db57 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -24,7 +24,11 @@ func execute(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "failed to instantiate store") } - store.WriteMany(Config.Configs) + err = store.PutMany(Config.Configs) + + if err != nil { + return errors.Wrap(err, "failed to write param") + } return nil } diff --git a/store/ssmstore.go b/store/ssmstore.go index b561c11..5e3ca85 100644 --- a/store/ssmstore.go +++ b/store/ssmstore.go @@ -1,11 +1,11 @@ package store import ( - "log" "strconv" "strings" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/client" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" "github.com/aws/aws-sdk-go/service/ssm/ssmiface" @@ -13,6 +13,11 @@ import ( var _ Store = &SSMStore{} +var ( + numberOfRetries = 10 + throttleDelay = client.DefaultRetryerMinRetryDelay +) + type SSMStore struct { svc ssmiface.SSMAPI } @@ -20,44 +25,47 @@ type SSMStore struct { func NewSSMStore() (*SSMStore, error) { ssmSession := session.Must(session.NewSession()) - svc := ssm.New(ssmSession) + retryer := client.DefaultRetryer{ + NumMaxRetries: numberOfRetries, + MinThrottleDelay: throttleDelay, + } + + svc := ssm.New(ssmSession, &aws.Config{ + Retryer: retryer, + }) return &SSMStore{ svc: svc, }, nil } -func (s *SSMStore) WriteMany(input []ConfigInput) error { - log.Printf("%v", input) - return nil -} - -func (s *SSMStore) Write(input ConfigInput) error { - version := 1 - current, err := s.Read(input.Key) +func (s *SSMStore) PutMany(input []ConfigInput) error { + for _, config := range input { + err := s.Put(config) - if err != nil && err != ConfigNotFoundError { - return err + if err != nil { + return err + } } - if err == nil { - version = current.Metadata.Version + 1 - } + return nil +} +func (s *SSMStore) Put(input ConfigInput) error { configType := "String" + if input.Secret == true { configType = "SecureString" } putParameterInput := &ssm.PutParameterInput{ - Name: aws.String(input.Key), - Type: aws.String(configType), - Value: aws.String(input.Value), - Overwrite: aws.Bool(true), - Description: aws.String(strconv.Itoa(version)), + Name: aws.String(input.Key), + Type: aws.String(configType), + Value: aws.String(input.Value), + Overwrite: aws.Bool(true), } - _, err = s.svc.PutParameter(putParameterInput) + _, err := s.svc.PutParameter(putParameterInput) if err != nil { return err @@ -67,7 +75,8 @@ func (s *SSMStore) Write(input ConfigInput) error { } func (s *SSMStore) Delete(key string) error { - _, err := s.Read(key) + _, err := s.Get(key) + if err != nil { return err } @@ -84,15 +93,15 @@ func (s *SSMStore) Delete(key string) error { return nil } -func (s *SSMStore) ReadMany(keys []string) ([]Config, error) { +func (s *SSMStore) GetMany(keys []string) ([]Config, error) { return nil, nil } -func (s *SSMStore) ReadAll() ([]Config, error) { +func (s *SSMStore) GetAll() ([]Config, error) { return nil, nil } -func (s *SSMStore) Read(key string) (Config, error) { +func (s *SSMStore) Get(key string) (Config, error) { getParametersInput := &ssm.GetParametersInput{ Names: []*string{aws.String(key)}, WithDecryption: aws.Bool(true), diff --git a/store/store.go b/store/store.go index cdf34a8..15147d7 100644 --- a/store/store.go +++ b/store/store.go @@ -28,10 +28,10 @@ var ( ) type Store interface { - Write(input ConfigInput) error - WriteMany(input []ConfigInput) error - Read(key string) (Config, error) - ReadMany(keys []string) ([]Config, error) - ReadAll() ([]Config, error) + Put(input ConfigInput) error + PutMany(input []ConfigInput) error + Get(key string) (Config, error) + GetMany(keys []string) ([]Config, error) + GetAll() ([]Config, error) Delete(key string) error }