Skip to content

Commit

Permalink
Merge pull request #194 from tony24681379/ssm
Browse files Browse the repository at this point in the history
feat: add ssm put and delete
  • Loading branch information
kaplanelad authored Jan 21, 2024
2 parents 01e94e1 + 09c7f74 commit 0ea7d8f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ aws_secretsmanager:
path: /prod/billing-svc/vars/mg
```

## AWS Paramstore
## AWS Parameter store

### Authentication

Expand All @@ -657,8 +657,8 @@ Your standard `AWS_DEFAULT_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`
### Features

- Sync - `no`
- Mapping - `yes`
- Modes - `read`, [write: accepting PR](https://github.com/spectralops/teller)
- Mapping - `no`
- Modes - `read+write+delete`
- Key format
- `env` - path based
- `decrypt` - available in this provider, will use KMS automatically
Expand Down
39 changes: 31 additions & 8 deletions pkg/providers/aws_ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/spectralops/teller/pkg/core"
"github.com/spectralops/teller/pkg/logging"
)

type AWSSSMClient interface {
GetParameter(ctx context.Context, params *ssm.GetParameterInput, optFns ...func(*ssm.Options)) (*ssm.GetParameterOutput, error)
PutParameter(ctx context.Context, params *ssm.PutParameterInput, optFns ...func(*ssm.Options)) (*ssm.PutParameterOutput, error)
DeleteParameter(ctx context.Context, params *ssm.DeleteParameterInput, optFns ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error)
}
type AWSSSM struct {
client AWSSSMClient
Expand All @@ -22,7 +25,7 @@ type AWSSSM struct {

const awsssmName = "aws_ssm"

//nolint
// nolint
func init() {
metaInfo := core.MetaInfo{
Description: "AWS SSM (aka paramstore)",
Expand All @@ -36,7 +39,7 @@ func init() {
path: /prod/foobar
decrypt: true
`,
Ops: core.OpMatrix{Get: true},
Ops: core.OpMatrix{Get: true, Put: true, Delete: true},
}
RegisterProvider(metaInfo, NewAWSSSM)
}
Expand Down Expand Up @@ -66,23 +69,43 @@ func NewAWSSSM(logger logging.Logger) (core.Provider, error) {
return &AWSSSM{client: client, logger: logger}, nil
}

func (a *AWSSSM) Put(p core.KeyPath, val string) error {
return fmt.Errorf("provider %q does not implement write yet", awsssmName)
func (a *AWSSSM) Put(kp core.KeyPath, val string) error {
_, err := a.client.PutParameter(context.TODO(), &ssm.PutParameterInput{
Name: &kp.Path,
Value: &val,
Overwrite: true,
Type: types.ParameterTypeString,
})
if err != nil {
return err
}

return nil
}
func (a *AWSSSM) PutMapping(p core.KeyPath, m map[string]string) error {
return fmt.Errorf("provider %q does not implement write yet", awsssmName)

func (a *AWSSSM) PutMapping(kp core.KeyPath, m map[string]string) error {
for k, v := range m {
ap := kp.SwitchPath(k)
err := a.Put(ap, v)
if err != nil {
return err
}
}

return nil
}

func (a *AWSSSM) GetMapping(kp core.KeyPath) ([]core.EnvEntry, error) {
return nil, fmt.Errorf("does not support full env sync (path: %s)", kp.Path)
}

func (a *AWSSSM) Delete(kp core.KeyPath) error {
return fmt.Errorf("%s does not implement delete yet", awsssmName)
_, err := a.client.DeleteParameter(context.TODO(), &ssm.DeleteParameterInput{Name: &kp.Path})
return err
}

func (a *AWSSSM) DeleteMapping(kp core.KeyPath) error {
return fmt.Errorf("%s does not implement delete yet", awsssmName)
return fmt.Errorf("does not support full env sync (path: %s)", kp.Path)
}

func (a *AWSSSM) Get(p core.KeyPath) (*core.EnvEntry, error) {
Expand Down
40 changes: 40 additions & 0 deletions pkg/providers/mock_providers/aws_ssm_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ea7d8f

Please sign in to comment.