Пример #1
0
func TestAfterRetryRefreshCreds(t *testing.T) {
	os.Clearenv()
	credProvider := &mockCredsProvider{}
	svc := NewService(&Config{Credentials: credentials.NewCredentials(credProvider), MaxRetries: 1})

	svc.Handlers.Clear()
	svc.Handlers.ValidateResponse.PushBack(func(r *Request) {
		r.Error = &APIError{Code: "UnknownError"}
		r.HTTPResponse = &http.Response{StatusCode: 400}
	})
	svc.Handlers.UnmarshalError.PushBack(func(r *Request) {
		r.Error = &APIError{Code: "ExpiredTokenException"}
	})
	svc.Handlers.AfterRetry.PushBack(func(r *Request) {
		AfterRetryHandler(r)
	})

	assert.True(t, svc.Config.Credentials.IsExpired(), "Expect to start out expired")
	assert.False(t, credProvider.retreiveCalled)

	req := NewRequest(svc, &Operation{Name: "Operation"}, nil, nil)
	req.Send()

	assert.True(t, svc.Config.Credentials.IsExpired())
	assert.False(t, credProvider.retreiveCalled)

	_, err := svc.Config.Credentials.Get()
	assert.NoError(t, err)
	assert.True(t, credProvider.retreiveCalled)
}
Пример #2
0
func (c *KMSCredential) KMS() security.KMS {
	config := &aws.Config{
		Credentials: credentials.NewCredentials(c),
		Region:      c.Region,
	}
	return &KMS{
		kms:   kms.New(config),
		keyID: c.KeyID,
	}
}
Пример #3
0
func KMS(c *Crypt) *kms.KMS {
	return kms.New(&aws.Config{
		Credentials: credentials.NewCredentials(&Credentials{Crypt: c}),
		Region:      c.AwsRegion,
	})
}