Explorar o código

Refactor PutParameter to use context

Signed-off-by: Marcus Dantas <marcus.dantas@engineerbetter.com>
Co-authored-by: Nick Ruffles <nick.ruffles@engineerbetter.com>
Marcus Dantas %!s(int64=3) %!d(string=hai) anos
pai
achega
5c08dd8683

+ 9 - 7
pkg/provider/aws/parameterstore/fake/fake.go

@@ -16,17 +16,19 @@ package fake
 import (
 	"fmt"
 
+	"github.com/aws/aws-sdk-go/aws"
+	"github.com/aws/aws-sdk-go/aws/request"
 	"github.com/aws/aws-sdk-go/service/ssm"
 	"github.com/google/go-cmp/cmp"
 )
 
 // Client implements the aws parameterstore interface.
 type Client struct {
-	valFn          func(*ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
-	PutParameterFn PutParameterFn
+	valFn                     func(*ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
+	PutParameterWithContextFn PutParameterWithContextFn
 }
 
-type PutParameterFn func(*ssm.PutParameterInput) (*ssm.PutParameterOutput, error)
+type PutParameterWithContextFn func(aws.Context, *ssm.PutParameterInput, ...request.Option) (*ssm.PutParameterOutput, error)
 
 func (sm *Client) GetParameter(in *ssm.GetParameterInput) (*ssm.GetParameterOutput, error) {
 	return sm.valFn(in)
@@ -36,12 +38,12 @@ func (sm *Client) DescribeParameters(*ssm.DescribeParametersInput) (*ssm.Describ
 	return nil, nil
 }
 
-func (sm *Client) PutParameter(input *ssm.PutParameterInput) (*ssm.PutParameterOutput, error) {
-	return sm.PutParameterFn(input)
+func (sm *Client) PutParameterWithContext(ctx aws.Context, input *ssm.PutParameterInput, options ...request.Option) (*ssm.PutParameterOutput, error) {
+	return sm.PutParameterWithContextFn(ctx, input, options...)
 }
 
-func NewPutParameterFn(output *ssm.PutParameterOutput, err error) PutParameterFn {
-	return func(*ssm.PutParameterInput) (*ssm.PutParameterOutput, error) {
+func NewPutParameterWithContextFn(output *ssm.PutParameterOutput, err error) PutParameterWithContextFn {
+	return func(aws.Context, *ssm.PutParameterInput, ...request.Option) (*ssm.PutParameterOutput, error) {
 		return output, err
 	}
 }

+ 3 - 2
pkg/provider/aws/parameterstore/parameterstore.go

@@ -21,6 +21,7 @@ import (
 	"strings"
 
 	"github.com/aws/aws-sdk-go/aws"
+	"github.com/aws/aws-sdk-go/aws/request"
 	"github.com/aws/aws-sdk-go/aws/session"
 	"github.com/aws/aws-sdk-go/service/ssm"
 	"github.com/tidwall/gjson"
@@ -45,7 +46,7 @@ type ParameterStore struct {
 type PMInterface interface {
 	GetParameter(*ssm.GetParameterInput) (*ssm.GetParameterOutput, error)
 	DescribeParameters(*ssm.DescribeParametersInput) (*ssm.DescribeParametersOutput, error)
-	PutParameter(*ssm.PutParameterInput) (*ssm.PutParameterOutput, error)
+	PutParameterWithContext(aws.Context, *ssm.PutParameterInput, ...request.Option) (*ssm.PutParameterOutput, error)
 }
 
 const (
@@ -70,7 +71,7 @@ func (pm *ParameterStore) SetSecret(ctx context.Context, value []byte, remoteRef
 		Type:  &parameterType,
 	}
 
-	_, err := pm.client.PutParameter(&secretRequest)
+	_, err := pm.client.PutParameterWithContext(ctx, &secretRequest)
 	if err != nil {
 		return err
 	}

+ 2 - 2
pkg/provider/aws/parameterstore/parameterstore_test.go

@@ -116,7 +116,7 @@ func TestPushSecret(t *testing.T) {
 			args: args{
 				store: makeValidParameterStore().Spec.Provider.AWS,
 				client: fakeps.Client{
-					PutParameterFn: fakeps.NewPutParameterFn(putParameterOutput, nil),
+					PutParameterWithContextFn: fakeps.NewPutParameterWithContextFn(putParameterOutput, nil),
 				},
 			},
 			want: want{
@@ -128,7 +128,7 @@ func TestPushSecret(t *testing.T) {
 			args: args{
 				store: makeValidParameterStore().Spec.Provider.AWS,
 				client: fakeps.Client{
-					PutParameterFn: fakeps.NewPutParameterFn(putParameterOutput, invalidPerameters),
+					PutParameterWithContextFn: fakeps.NewPutParameterWithContextFn(putParameterOutput, invalidPerameters),
 				},
 			},
 			want: want{