diff --git a/cache.go b/cache.go index f74a804..7df3976 100644 --- a/cache.go +++ b/cache.go @@ -1,6 +1,7 @@ package psadm import ( + "context" "fmt" "time" @@ -15,14 +16,14 @@ type CachedClient struct { var _ client = &CachedClient{} -func (c *CachedClient) GetParameterWithDescription(key string) (*Parameter, error) { +func (c *CachedClient) GetParameterWithDescription(ctx context.Context, key string) (*Parameter, error) { ck := buildCacheKey("GetParameterWithDescription", key) if v, found := c.cache.Get(ck); found { return v.(*Parameter), nil } - param, err := c.client.GetParameterWithDescription(key) + param, err := c.client.GetParameterWithDescription(ctx, key) if err != nil { return nil, err } @@ -31,14 +32,14 @@ func (c *CachedClient) GetParameterWithDescription(key string) (*Parameter, erro return param, nil } -func (c *CachedClient) GetParameter(key string) (string, error) { +func (c *CachedClient) GetParameter(ctx context.Context, key string) (string, error) { ck := buildCacheKey("GetParameter", key) if v, found := c.cache.Get(ck); found { return v.(string), nil } - param, err := c.client.GetParameter(key) + param, err := c.client.GetParameter(ctx, key) if err != nil { return "", err } @@ -47,14 +48,14 @@ func (c *CachedClient) GetParameter(key string) (string, error) { return param, nil } -func (c *CachedClient) GetParameterByTime(key string, at time.Time) (*Parameter, error) { +func (c *CachedClient) GetParameterByTime(ctx context.Context, key string, at time.Time) (*Parameter, error) { ck := fmt.Sprintf("%s/%s/%d", "GetParameterByTime", key, at.Unix()) if v, found := c.cache.Get(ck); found { return v.(*Parameter), nil } - param, err := c.client.GetParameterByTime(key, at) + param, err := c.client.GetParameterByTime(ctx, key, at) if err != nil { return nil, err } @@ -63,14 +64,14 @@ func (c *CachedClient) GetParameterByTime(key string, at time.Time) (*Parameter, return param, nil } -func (c *CachedClient) GetParametersByPath(pathPrefix string) ([]*Parameter, error) { +func (c *CachedClient) GetParametersByPath(ctx context.Context, pathPrefix string) ([]*Parameter, error) { ck := buildCacheKey("GetParametersByPath", pathPrefix) if v, found := c.cache.Get(ck); found { return v.([]*Parameter), nil } - params, err := c.client.GetParametersByPath(pathPrefix) + params, err := c.client.GetParametersByPath(ctx, pathPrefix) if err != nil { return nil, err } @@ -80,8 +81,8 @@ func (c *CachedClient) GetParametersByPath(pathPrefix string) ([]*Parameter, err } // PutParameter forwards a call to the underlying client. It doesn't do any caching. -func (c *CachedClient) PutParameter(p *Parameter, overrite bool) error { - return c.client.PutParameter(p, overrite) +func (c *CachedClient) PutParameter(ctx context.Context, p *Parameter, overwrite bool) error { + return c.client.PutParameter(ctx, p, overwrite) } func buildCacheKey(prefix, key string) string { diff --git a/cache_test.go b/cache_test.go index 3c688c5..52c06a1 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1,14 +1,16 @@ package psadm import ( + "context" "testing" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ssm" - gomock "github.com/golang/mock/gomock" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/patrickmn/go-cache" "github.com/stretchr/testify/assert" + gomock "go.uber.org/mock/gomock" ) func TestCachedClient(t *testing.T) { @@ -18,12 +20,12 @@ func TestCachedClient(t *testing.T) { t.Run("GetParameter", func(t *testing.T) { mockSSM := NewMockssmClient(mockctrl) mockSSM.EXPECT(). - GetParameter(&ssm.GetParameterInput{ + GetParameter(gomock.Any(), &ssm.GetParameterInput{ Name: aws.String("key/1/2/3"), WithDecryption: aws.Bool(true), }). Return(&ssm.GetParameterOutput{ - Parameter: &ssm.Parameter{ + Parameter: &types.Parameter{ Value: aws.String("value"), }, }, nil) @@ -31,7 +33,7 @@ func TestCachedClient(t *testing.T) { c := cache.New(time.Minute, 10*time.Minute) client := (&Client{SSM: mockSSM}).CachedClient(c) - v, err := client.GetParameter("key/1/2/3") + v, err := client.GetParameter(context.TODO(), "key/1/2/3") assert.Equal("value", v) assert.NoError(err) diff --git a/client.go b/client.go index 29a863a..519d539 100644 --- a/client.go +++ b/client.go @@ -2,21 +2,22 @@ package psadm import ( + "context" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ssm" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/patrickmn/go-cache" "github.com/pkg/errors" ) // ssmClient allows us to inject a fake API client for testing. type ssmClient interface { - DescribeParameters(*ssm.DescribeParametersInput) (*ssm.DescribeParametersOutput, error) - GetParameter(*ssm.GetParameterInput) (*ssm.GetParameterOutput, error) - GetParameterHistory(*ssm.GetParameterHistoryInput) (*ssm.GetParameterHistoryOutput, error) - PutParameter(*ssm.PutParameterInput) (*ssm.PutParameterOutput, error) + DescribeParameters(context.Context, *ssm.DescribeParametersInput, ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error) + GetParameter(context.Context, *ssm.GetParameterInput, ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) + GetParameterHistory(context.Context, *ssm.GetParameterHistoryInput, ...func(*ssm.Options)) (*ssm.GetParameterHistoryOutput, error) + PutParameter(context.Context, *ssm.PutParameterInput, ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) } // Parameter is the parameter exported by psadm. @@ -31,11 +32,11 @@ type Parameter struct { // client is an internal interface that can be chained with the standard client. type client interface { - GetParameterWithDescription(string) (*Parameter, error) - GetParameter(string) (string, error) - GetParameterByTime(string, time.Time) (*Parameter, error) - PutParameter(*Parameter, bool) error - GetParametersByPath(string) ([]*Parameter, error) + GetParameterWithDescription(context.Context, string) (*Parameter, error) + GetParameter(context.Context, string) (string, error) + GetParameterByTime(context.Context, string, time.Time) (*Parameter, error) + PutParameter(context.Context, *Parameter, bool) error + GetParametersByPath(context.Context, string) ([]*Parameter, error) } // Client wraps the SSM client for psadm. @@ -44,9 +45,9 @@ type Client struct { } // NewClient returns a psadm client. -func NewClient(sess *session.Session) *Client { +func NewClient(cfg aws.Config) *Client { return &Client{ - SSM: ssm.New(sess), + SSM: ssm.NewFromConfig(cfg), } } @@ -65,12 +66,13 @@ func (c *Client) CachedClient(cache *cache.Cache) *CachedClient { } } -func (c *Client) GetParameterWithDescription(key string) (*Parameter, error) { - desc, err := c.describeParameters([]*ssm.ParameterStringFilter{ +func (c *Client) GetParameterWithDescription(ctx context.Context, key string) (*Parameter, error) { + keyName := string(types.ParametersFilterKeyName) + desc, err := c.describeParameters(ctx, []types.ParameterStringFilter{ { - Key: aws.String(ssm.ParametersFilterKeyName), + Key: &keyName, Option: aws.String("Equals"), - Values: []*string{aws.String(key)}, + Values: []string{key}, }, }) if err != nil { @@ -80,37 +82,38 @@ func (c *Client) GetParameterWithDescription(key string) (*Parameter, error) { return nil, errors.Errorf("'%s' is not found.", key) } - val, err := c.getParameter(key) + val, err := c.getParameter(ctx, key) if err != nil { return nil, errors.Wrapf(err, "failed to get parameter '%s'", key) } p := desc[0] return &Parameter{ - Description: aws.StringValue(p.Description), - KMSKeyID: aws.StringValue(p.KeyId), - Name: aws.StringValue(p.Name), - Type: aws.StringValue(p.Type), - Value: aws.StringValue(val.Parameter.Value), + Description: aws.ToString(p.Description), + KMSKeyID: aws.ToString(p.KeyId), + Name: aws.ToString(p.Name), + Type: string(p.Type), + Value: aws.ToString(val.Parameter.Value), }, nil } // GetParameter returns the decrypted parameter. -func (c *Client) GetParameter(key string) (string, error) { - resp, err := c.getParameter(key) +func (c *Client) GetParameter(ctx context.Context, key string) (string, error) { + resp, err := c.getParameter(ctx, key) if err != nil { return "", errors.Wrapf(err, "failed to get parameter '%s'", key) } - return aws.StringValue(resp.Parameter.Value), nil + return aws.ToString(resp.Parameter.Value), nil } // GetParameterByTime returns the latest parameter. -func (c *Client) GetParameterByTime(key string, at time.Time) (*Parameter, error) { - desc, err := c.describeParameters([]*ssm.ParameterStringFilter{ +func (c *Client) GetParameterByTime(ctx context.Context, key string, at time.Time) (*Parameter, error) { + keyName := string(types.ParametersFilterKeyName) + desc, err := c.describeParameters(ctx, []types.ParameterStringFilter{ { - Key: aws.String(ssm.ParametersFilterKeyName), + Key: &keyName, Option: aws.String("Equals"), - Values: []*string{aws.String(key)}, + Values: []string{key}, }, }) if err != nil { @@ -120,14 +123,14 @@ func (c *Client) GetParameterByTime(key string, at time.Time) (*Parameter, error return nil, errors.Errorf("'%s' is not found.", key) } - latest := aws.TimeValue(desc[0].LastModifiedDate) + latest := aws.ToTime(desc[0].LastModifiedDate) if latest.Before(at) { - return c.GetParameterWithDescription(key) + return c.GetParameterWithDescription(ctx, key) } // dig into history - history, err := c.getParameterHistory(key) + history, err := c.getParameterHistory(ctx, key) if err != nil { return nil, err } @@ -136,32 +139,28 @@ func (c *Client) GetParameterByTime(key string, at time.Time) (*Parameter, error } // history is sorted by LastModifiedDate in ascending order - var p *ssm.ParameterHistory + var p types.ParameterHistory for _, h := range history { - if aws.TimeValue(h.LastModifiedDate).After(at) { + if aws.ToTime(h.LastModifiedDate).After(at) { continue } p = h } - if p == nil { - return nil, errors.Errorf("'%s' is not found at give time.", key) - } - return &Parameter{ - Description: aws.StringValue(p.Description), - KMSKeyID: aws.StringValue(p.KeyId), - Name: aws.StringValue(p.Name), - Type: aws.StringValue(p.Type), - Value: aws.StringValue(p.Value), + Description: aws.ToString(p.Description), + KMSKeyID: aws.ToString(p.KeyId), + Name: aws.ToString(p.Name), + Type: string(p.Type), + Value: aws.ToString(p.Value), }, nil } // PutParameter puts param into Parameter Store. -func (c *Client) PutParameter(param *Parameter, overwrite bool) error { +func (c *Client) PutParameter(ctx context.Context, param *Parameter, overwrite bool) error { input := &ssm.PutParameterInput{ Name: aws.String(param.Name), - Type: aws.String(param.Type), + Type: types.ParameterType(param.Type), Value: aws.String(param.Value), Overwrite: aws.Bool(overwrite), } @@ -171,64 +170,66 @@ func (c *Client) PutParameter(param *Parameter, overwrite bool) error { if param.KMSKeyID != "" { input.KeyId = aws.String(param.KMSKeyID) } - _, err := c.SSM.PutParameter(input) + _, err := c.SSM.PutParameter(ctx, input) return errors.Wrap(err, "failed to put parameters") } -func (c *Client) getParameter(key string) (*ssm.GetParameterOutput, error) { - return c.SSM.GetParameter(&ssm.GetParameterInput{ +func (c *Client) getParameter(ctx context.Context, key string) (*ssm.GetParameterOutput, error) { + return c.SSM.GetParameter(ctx, &ssm.GetParameterInput{ Name: aws.String(key), WithDecryption: aws.Bool(true), }) } // GetParametersByPath gets all parameters having given path prefix. -func (c *Client) GetParametersByPath(pathPrefix string) ([]*Parameter, error) { - var filters []*ssm.ParameterStringFilter +func (c *Client) GetParametersByPath(ctx context.Context, pathPrefix string) ([]*Parameter, error) { + var filters []types.ParameterStringFilter + + keyName := string(types.ParametersFilterKeyName) if pathPrefix != "" { - filters = []*ssm.ParameterStringFilter{ + filters = []types.ParameterStringFilter{ { - Key: aws.String(ssm.ParametersFilterKeyName), + Key: &keyName, Option: aws.String("BeginsWith"), - Values: []*string{aws.String(pathPrefix)}, + Values: []string{pathPrefix}, }, } } - desc, err := c.describeParameters(filters) + desc, err := c.describeParameters(ctx, filters) if err != nil { return nil, err } var params []*Parameter for _, p := range desc { - val, err := c.getParameter(*p.Name) + val, err := c.getParameter(ctx, *p.Name) if err != nil { return nil, errors.Wrap(err, "failed to get parameters") } params = append(params, &Parameter{ - Description: aws.StringValue(p.Description), - KMSKeyID: aws.StringValue(p.KeyId), - Name: aws.StringValue(p.Name), - Type: aws.StringValue(p.Type), - Value: aws.StringValue(val.Parameter.Value), + Description: aws.ToString(p.Description), + KMSKeyID: aws.ToString(p.KeyId), + Name: aws.ToString(p.Name), + Type: string(p.Type), + Value: aws.ToString(val.Parameter.Value), }) } return params, nil } -func (c *Client) getParameterHistory(key string) ([]*ssm.ParameterHistory, error) { +func (c *Client) getParameterHistory(ctx context.Context, key string) ([]types.ParameterHistory, error) { input := &ssm.GetParameterHistoryInput{ Name: aws.String(key), WithDecryption: aws.Bool(true), } - var history []*ssm.ParameterHistory + var history []types.ParameterHistory for { - resp, err := c.SSM.GetParameterHistory(input) + resp, err := c.SSM.GetParameterHistory(ctx, input) if err != nil { return nil, errors.Wrap(err, "failed to get parameter history") } @@ -243,14 +244,14 @@ func (c *Client) getParameterHistory(key string) ([]*ssm.ParameterHistory, error return history, nil } -func (c *Client) describeParameters(filters []*ssm.ParameterStringFilter) ([]*ssm.ParameterMetadata, error) { +func (c *Client) describeParameters(ctx context.Context, filters []types.ParameterStringFilter) ([]types.ParameterMetadata, error) { input := &ssm.DescribeParametersInput{ ParameterFilters: filters, } - var params []*ssm.ParameterMetadata + var params []types.ParameterMetadata for { - desc, err := c.SSM.DescribeParameters(input) + desc, err := c.SSM.DescribeParameters(ctx, input) if err != nil { return nil, errors.Wrap(err, "failed to describe parameters") } diff --git a/client_test.go b/client_test.go index 43d374a..d963997 100644 --- a/client_test.go +++ b/client_test.go @@ -1,12 +1,14 @@ package psadm import ( + "context" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ssm" - gomock "github.com/golang/mock/gomock" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/stretchr/testify/assert" + gomock "go.uber.org/mock/gomock" ) func TestClient(t *testing.T) { @@ -16,18 +18,18 @@ func TestClient(t *testing.T) { t.Run("GetParameter", func(t *testing.T) { mockSSM := NewMockssmClient(mockctrl) mockSSM.EXPECT(). - GetParameter(&ssm.GetParameterInput{ + GetParameter(gomock.Any(), &ssm.GetParameterInput{ Name: aws.String("key/1/2/3"), WithDecryption: aws.Bool(true), }). Return(&ssm.GetParameterOutput{ - Parameter: &ssm.Parameter{ + Parameter: &types.Parameter{ Value: aws.String("value"), }, }, nil) client := &Client{SSM: mockSSM} - v, err := client.GetParameter("key/1/2/3") + v, err := client.GetParameter(context.TODO(), "key/1/2/3") assert.Equal("value", v) assert.NoError(err) }) diff --git a/cmd/psadm/export.go b/cmd/psadm/export.go index 5e7f5a9..50418cf 100644 --- a/cmd/psadm/export.go +++ b/cmd/psadm/export.go @@ -1,9 +1,10 @@ package main import ( + "context" "fmt" - "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go-v2/config" "github.com/goccy/go-yaml" "github.com/nabeken/psadm" "github.com/pkg/errors" @@ -14,9 +15,15 @@ type ExportCommand struct { } func (cmd *ExportCommand) Execute(args []string) error { - client := psadm.NewClient(session.Must(session.NewSession())) + ctx := context.Background() + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return err + } + + client := psadm.NewClient(cfg) - params, err := client.GetParametersByPath(cmd.KeyPrefix) + params, err := client.GetParametersByPath(ctx, cmd.KeyPrefix) if err != nil { return err } diff --git a/cmd/psadm/get.go b/cmd/psadm/get.go index e54db3e..0f68ab6 100644 --- a/cmd/psadm/get.go +++ b/cmd/psadm/get.go @@ -1,10 +1,11 @@ package main import ( + "context" "fmt" "time" - "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go-v2/config" "github.com/goccy/go-yaml" "github.com/nabeken/psadm" "github.com/pkg/errors" @@ -16,23 +17,30 @@ type GetCommand struct { } func (cmd *GetCommand) Execute(args []string) error { + var err error + if len(args) == 0 { return errors.New("You must specify a KEY to get.") } - client := psadm.NewClient(session.Must(session.NewSession())) + ctx := context.Background() + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return err + } + + client := psadm.NewClient(cfg) var param *psadm.Parameter - var err error if cmd.At == "" { - param, err = client.GetParameterWithDescription(args[0]) + param, err = client.GetParameterWithDescription(ctx, args[0]) } else { var at time.Time at, err = time.Parse(time.RFC3339, cmd.At) if err != nil { return errors.Wrap(err, "failed to parse `at'.") } - param, err = client.GetParameterByTime(args[0], at) + param, err = client.GetParameterByTime(ctx, args[0], at) } if err != nil { return err diff --git a/cmd/psadm/import.go b/cmd/psadm/import.go index 646937b..4f15778 100644 --- a/cmd/psadm/import.go +++ b/cmd/psadm/import.go @@ -1,13 +1,13 @@ package main import ( + "context" "fmt" "io" "os" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ssm" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/goccy/go-yaml" "github.com/nabeken/psadm" "github.com/pkg/errors" @@ -41,16 +41,23 @@ func (cmd *ImportCommand) Execute(args []string) error { return errors.Wrap(err, "failed to unmarshal from YAML") } - client := psadm.NewClient(session.Must(session.NewSession())) + ctx := context.Background() + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return err + } + + client := psadm.NewClient(cfg) // function to update actualRun := func(p *psadm.Parameter) error { - if err := client.PutParameter(p, cmd.Overwrite); err != nil { - if awsErr, ok := errors.Cause(err).(awserr.Error); ok { - if awsErr.Code() == ssm.ErrCodeParameterAlreadyExists && cmd.SkipExist { - return nil - } + if err := client.PutParameter(ctx, p, cmd.Overwrite); err != nil { + var ae *types.ParameterAlreadyExists + + if errors.As(err, &ae) && cmd.SkipExist { + return nil } + return err } return nil @@ -66,7 +73,7 @@ func (cmd *ImportCommand) Execute(args []string) error { } for _, p := range params { - if p.Type == ssm.ParameterTypeSecureString && p.KMSKeyID == "" { + if p.Type == string(types.ParameterTypeSecureString) && p.KMSKeyID == "" { p.KMSKeyID = cmd.DefaultKMSKeyID } if err := runF(p); err != nil { diff --git a/go.mod b/go.mod index aa62ce4..f9fe30e 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,7 @@ module github.com/nabeken/psadm go 1.21 require ( - github.com/aws/aws-sdk-go v1.51.25 github.com/goccy/go-yaml v1.11.3 - github.com/golang/mock v1.6.0 github.com/jessevdk/go-flags v1.5.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/errors v0.9.1 @@ -27,3 +25,24 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +require ( + github.com/aws/aws-sdk-go-v2 v1.26.1 + github.com/aws/aws-sdk-go-v2/config v1.27.10 + github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5 + go.uber.org/mock v0.4.0 +) + +require ( + github.com/aws/aws-sdk-go-v2/credentials v1.17.10 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.20.4 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect + github.com/aws/smithy-go v1.20.2 // indirect +) diff --git a/go.sum b/go.sum index 921b789..f1d3722 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,31 @@ -github.com/aws/aws-sdk-go v1.51.25 h1:DjTT8mtmsachhV6yrXR8+yhnG6120dazr720nopRsls= -github.com/aws/aws-sdk-go v1.51.25/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= +github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= +github.com/aws/aws-sdk-go-v2/config v1.27.10 h1:PS+65jThT0T/snC5WjyfHHyUgG+eBoupSDV+f838cro= +github.com/aws/aws-sdk-go-v2/config v1.27.10/go.mod h1:BePM7Vo4OBpHreKRUMuDXX+/+JWP38FLkzl5m27/Jjs= +github.com/aws/aws-sdk-go-v2/credentials v1.17.10 h1:qDZ3EA2lv1KangvQB6y258OssCHD0xvaGiEDkG4X/10= +github.com/aws/aws-sdk-go-v2/credentials v1.17.10/go.mod h1:6t3sucOaYDwDssHQa0ojH1RpmVmF5/jArkye1b2FKMI= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 h1:FVJ0r5XTHSmIHJV6KuDmdYhEpvlHpiSd38RQWhut5J4= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1/go.mod h1:zusuAeqezXzAB24LGuzuekqMAEgWkVYukBec3kr3jUg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 h1:aw39xVGeRWlWx9EzGVnhOR4yOjQDHPQ6o6NmBlscyQg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5/go.mod h1:FSaRudD0dXiMPK2UjknVwwTYyZMRsHv3TtkabsZih5I= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 h1:PG1F3OD1szkuQPzDw3CIQsRIrtTlUC3lP84taWzHlq0= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5/go.mod h1:jU1li6RFryMz+so64PpKtudI+QzbKoIEivqdf6LNpOc= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 h1:ogRAwT1/gxJBcSWDMZlgyFUM962F51A5CRhDLbxLdmo= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7/go.mod h1:YCsIZhXfRPLFFCl5xxY+1T9RKzOKjCut+28JSX2DnAk= +github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5 h1:KBwyHzP2QG8J//hoGuPyHWZ5tgL1BzaoMURUkecpI4g= +github.com/aws/aws-sdk-go-v2/service/ssm v1.49.5/go.mod h1:Ebk/HZmGhxWKDVxM4+pwbxGjm3RQOQLMjAEosI3ss9Q= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.4 h1:WzFol5Cd+yDxPAdnzTA5LmpHYSWinhmSj4rQChV0ee8= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.4/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4/go.mod h1:mUYPBhaF2lGiukDEjJX2BLRRKTmoUSitGDUgM4tRxak= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 h1:cwIxeBttqPN3qkaAjcEcsh8NYr8n2HZPkcKgPAi1phU= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.6/go.mod h1:FZf1/nKNEkHdGGJP/cI2MoIMquumuRK6ol3QQJNDxmw= +github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= +github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,8 +39,6 @@ github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7a github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I= github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= @@ -44,38 +68,17 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/mock_client.go b/mock_client.go index 65e8d74..971b1b7 100644 --- a/mock_client.go +++ b/mock_client.go @@ -1,15 +1,21 @@ // Code generated by MockGen. DO NOT EDIT. // Source: client.go +// +// Generated by this command: +// +// mockgen -source=client.go -package psadm -destination mock_client.go +// // Package psadm is a generated GoMock package. package psadm import ( + context "context" reflect "reflect" time "time" - ssm "github.com/aws/aws-sdk-go/service/ssm" - gomock "github.com/golang/mock/gomock" + ssm "github.com/aws/aws-sdk-go-v2/service/ssm" + gomock "go.uber.org/mock/gomock" ) // MockssmClient is a mock of ssmClient interface. @@ -36,63 +42,83 @@ func (m *MockssmClient) EXPECT() *MockssmClientMockRecorder { } // DescribeParameters mocks base method. -func (m *MockssmClient) DescribeParameters(arg0 *ssm.DescribeParametersInput) (*ssm.DescribeParametersOutput, error) { +func (m *MockssmClient) DescribeParameters(arg0 context.Context, arg1 *ssm.DescribeParametersInput, arg2 ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DescribeParameters", arg0) + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DescribeParameters", varargs...) ret0, _ := ret[0].(*ssm.DescribeParametersOutput) ret1, _ := ret[1].(error) return ret0, ret1 } // DescribeParameters indicates an expected call of DescribeParameters. -func (mr *MockssmClientMockRecorder) DescribeParameters(arg0 interface{}) *gomock.Call { +func (mr *MockssmClientMockRecorder) DescribeParameters(arg0, arg1 any, arg2 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeParameters", reflect.TypeOf((*MockssmClient)(nil).DescribeParameters), arg0) + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeParameters", reflect.TypeOf((*MockssmClient)(nil).DescribeParameters), varargs...) } // GetParameter mocks base method. -func (m *MockssmClient) GetParameter(arg0 *ssm.GetParameterInput) (*ssm.GetParameterOutput, error) { +func (m *MockssmClient) GetParameter(arg0 context.Context, arg1 *ssm.GetParameterInput, arg2 ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParameter", arg0) + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetParameter", varargs...) ret0, _ := ret[0].(*ssm.GetParameterOutput) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParameter indicates an expected call of GetParameter. -func (mr *MockssmClientMockRecorder) GetParameter(arg0 interface{}) *gomock.Call { +func (mr *MockssmClientMockRecorder) GetParameter(arg0, arg1 any, arg2 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameter", reflect.TypeOf((*MockssmClient)(nil).GetParameter), arg0) + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameter", reflect.TypeOf((*MockssmClient)(nil).GetParameter), varargs...) } // GetParameterHistory mocks base method. -func (m *MockssmClient) GetParameterHistory(arg0 *ssm.GetParameterHistoryInput) (*ssm.GetParameterHistoryOutput, error) { +func (m *MockssmClient) GetParameterHistory(arg0 context.Context, arg1 *ssm.GetParameterHistoryInput, arg2 ...func(*ssm.Options)) (*ssm.GetParameterHistoryOutput, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParameterHistory", arg0) + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetParameterHistory", varargs...) ret0, _ := ret[0].(*ssm.GetParameterHistoryOutput) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParameterHistory indicates an expected call of GetParameterHistory. -func (mr *MockssmClientMockRecorder) GetParameterHistory(arg0 interface{}) *gomock.Call { +func (mr *MockssmClientMockRecorder) GetParameterHistory(arg0, arg1 any, arg2 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterHistory", reflect.TypeOf((*MockssmClient)(nil).GetParameterHistory), arg0) + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterHistory", reflect.TypeOf((*MockssmClient)(nil).GetParameterHistory), varargs...) } // PutParameter mocks base method. -func (m *MockssmClient) PutParameter(arg0 *ssm.PutParameterInput) (*ssm.PutParameterOutput, error) { +func (m *MockssmClient) PutParameter(arg0 context.Context, arg1 *ssm.PutParameterInput, arg2 ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutParameter", arg0) + varargs := []any{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PutParameter", varargs...) ret0, _ := ret[0].(*ssm.PutParameterOutput) ret1, _ := ret[1].(error) return ret0, ret1 } // PutParameter indicates an expected call of PutParameter. -func (mr *MockssmClientMockRecorder) PutParameter(arg0 interface{}) *gomock.Call { +func (mr *MockssmClientMockRecorder) PutParameter(arg0, arg1 any, arg2 ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutParameter", reflect.TypeOf((*MockssmClient)(nil).PutParameter), arg0) + varargs := append([]any{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutParameter", reflect.TypeOf((*MockssmClient)(nil).PutParameter), varargs...) } // Mockclient is a mock of client interface. @@ -119,75 +145,75 @@ func (m *Mockclient) EXPECT() *MockclientMockRecorder { } // GetParameter mocks base method. -func (m *Mockclient) GetParameter(arg0 string) (string, error) { +func (m *Mockclient) GetParameter(arg0 context.Context, arg1 string) (string, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParameter", arg0) + ret := m.ctrl.Call(m, "GetParameter", arg0, arg1) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParameter indicates an expected call of GetParameter. -func (mr *MockclientMockRecorder) GetParameter(arg0 interface{}) *gomock.Call { +func (mr *MockclientMockRecorder) GetParameter(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameter", reflect.TypeOf((*Mockclient)(nil).GetParameter), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameter", reflect.TypeOf((*Mockclient)(nil).GetParameter), arg0, arg1) } // GetParameterByTime mocks base method. -func (m *Mockclient) GetParameterByTime(arg0 string, arg1 time.Time) (*Parameter, error) { +func (m *Mockclient) GetParameterByTime(arg0 context.Context, arg1 string, arg2 time.Time) (*Parameter, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParameterByTime", arg0, arg1) + ret := m.ctrl.Call(m, "GetParameterByTime", arg0, arg1, arg2) ret0, _ := ret[0].(*Parameter) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParameterByTime indicates an expected call of GetParameterByTime. -func (mr *MockclientMockRecorder) GetParameterByTime(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockclientMockRecorder) GetParameterByTime(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterByTime", reflect.TypeOf((*Mockclient)(nil).GetParameterByTime), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterByTime", reflect.TypeOf((*Mockclient)(nil).GetParameterByTime), arg0, arg1, arg2) } // GetParameterWithDescription mocks base method. -func (m *Mockclient) GetParameterWithDescription(arg0 string) (*Parameter, error) { +func (m *Mockclient) GetParameterWithDescription(arg0 context.Context, arg1 string) (*Parameter, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParameterWithDescription", arg0) + ret := m.ctrl.Call(m, "GetParameterWithDescription", arg0, arg1) ret0, _ := ret[0].(*Parameter) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParameterWithDescription indicates an expected call of GetParameterWithDescription. -func (mr *MockclientMockRecorder) GetParameterWithDescription(arg0 interface{}) *gomock.Call { +func (mr *MockclientMockRecorder) GetParameterWithDescription(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterWithDescription", reflect.TypeOf((*Mockclient)(nil).GetParameterWithDescription), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParameterWithDescription", reflect.TypeOf((*Mockclient)(nil).GetParameterWithDescription), arg0, arg1) } // GetParametersByPath mocks base method. -func (m *Mockclient) GetParametersByPath(arg0 string) ([]*Parameter, error) { +func (m *Mockclient) GetParametersByPath(arg0 context.Context, arg1 string) ([]*Parameter, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetParametersByPath", arg0) + ret := m.ctrl.Call(m, "GetParametersByPath", arg0, arg1) ret0, _ := ret[0].([]*Parameter) ret1, _ := ret[1].(error) return ret0, ret1 } // GetParametersByPath indicates an expected call of GetParametersByPath. -func (mr *MockclientMockRecorder) GetParametersByPath(arg0 interface{}) *gomock.Call { +func (mr *MockclientMockRecorder) GetParametersByPath(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParametersByPath", reflect.TypeOf((*Mockclient)(nil).GetParametersByPath), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParametersByPath", reflect.TypeOf((*Mockclient)(nil).GetParametersByPath), arg0, arg1) } // PutParameter mocks base method. -func (m *Mockclient) PutParameter(arg0 *Parameter, arg1 bool) error { +func (m *Mockclient) PutParameter(arg0 context.Context, arg1 *Parameter, arg2 bool) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PutParameter", arg0, arg1) + ret := m.ctrl.Call(m, "PutParameter", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } // PutParameter indicates an expected call of PutParameter. -func (mr *MockclientMockRecorder) PutParameter(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockclientMockRecorder) PutParameter(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutParameter", reflect.TypeOf((*Mockclient)(nil).PutParameter), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutParameter", reflect.TypeOf((*Mockclient)(nil).PutParameter), arg0, arg1, arg2) } diff --git a/singleflight.go b/singleflight.go index b15f9ef..2e39b87 100644 --- a/singleflight.go +++ b/singleflight.go @@ -1,6 +1,7 @@ package psadm import ( + "context" "fmt" "time" @@ -15,45 +16,45 @@ type SingleflightClient struct { var _ client = &SingleflightClient{} -func (c *SingleflightClient) GetParameterWithDescription(key string) (*Parameter, error) { +func (c *SingleflightClient) GetParameterWithDescription(ctx context.Context, key string) (*Parameter, error) { ck := buildCacheKey("GetParameterWithDescription", key) v, err, _ := c.g.Do(ck, func() (interface{}, error) { - return c.client.GetParameterWithDescription(key) + return c.client.GetParameterWithDescription(ctx, key) }) return v.(*Parameter), err } -func (c *SingleflightClient) GetParameter(key string) (string, error) { +func (c *SingleflightClient) GetParameter(ctx context.Context, key string) (string, error) { ck := buildCacheKey("GetParameter", key) v, err, _ := c.g.Do(ck, func() (interface{}, error) { - return c.client.GetParameter(key) + return c.client.GetParameter(ctx, key) }) return v.(string), err } -func (c *SingleflightClient) GetParameterByTime(key string, at time.Time) (*Parameter, error) { +func (c *SingleflightClient) GetParameterByTime(ctx context.Context, key string, at time.Time) (*Parameter, error) { ck := fmt.Sprintf("%s/%s/%d", "GetParameterByTime", key, at.Unix()) v, err, _ := c.g.Do(ck, func() (interface{}, error) { - return c.client.GetParameterByTime(key, at) + return c.client.GetParameterByTime(ctx, key, at) }) return v.(*Parameter), err } -func (c *SingleflightClient) GetParametersByPath(pathPrefix string) ([]*Parameter, error) { +func (c *SingleflightClient) GetParametersByPath(ctx context.Context, pathPrefix string) ([]*Parameter, error) { ck := buildCacheKey("GetParametersByPath", pathPrefix) v, err, _ := c.g.Do(ck, func() (interface{}, error) { - return c.client.GetParametersByPath(pathPrefix) + return c.client.GetParametersByPath(ctx, pathPrefix) }) return v.([]*Parameter), err } // PutParameter forwards a call to the underlying client. It doesn't do any deduplication. -func (c *SingleflightClient) PutParameter(p *Parameter, overrite bool) error { - return c.client.PutParameter(p, overrite) +func (c *SingleflightClient) PutParameter(ctx context.Context, p *Parameter, overwrite bool) error { + return c.client.PutParameter(ctx, p, overwrite) } diff --git a/singleflight_test.go b/singleflight_test.go index 3107b0a..0c6a11c 100644 --- a/singleflight_test.go +++ b/singleflight_test.go @@ -1,16 +1,18 @@ package psadm import ( + "context" "log" "sync" "testing" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ssm" - gomock "github.com/golang/mock/gomock" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/ssm" + "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/patrickmn/go-cache" "github.com/stretchr/testify/assert" + gomock "go.uber.org/mock/gomock" ) func TestSingleflightCient(t *testing.T) { @@ -21,15 +23,15 @@ func TestSingleflightCient(t *testing.T) { client := &Client{SSM: mockSSM} ch := make(chan struct{}) - mockSSM.EXPECT().GetParameter(gomock.Any()). + mockSSM.EXPECT().GetParameter(gomock.Any(), gomock.Any()). // make sure the client only call the underlying client once Times(1). - DoAndReturn(func(_ *ssm.GetParameterInput) (*ssm.GetParameterOutput, error) { + DoAndReturn(func(_ context.Context, _ *ssm.GetParameterInput, _ ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) { log.Print("ssm client is waiting for goroutines launched...") <-ch log.Print("ssm client is going to return a result") return &ssm.GetParameterOutput{ - Parameter: &ssm.Parameter{ + Parameter: &types.Parameter{ Value: aws.String("value"), }, }, nil @@ -57,7 +59,7 @@ func TestSingleflightCient(t *testing.T) { // let the main goroutine check launched again cond.Signal() - actual, err := sfc.GetParameter("key") + actual, err := sfc.GetParameter(context.TODO(), "key") assert.NoError(err) assert.Equal("value", actual) }()