diff --git a/daemon.go b/daemon.go index 553d825..570d3c6 100644 --- a/daemon.go +++ b/daemon.go @@ -41,7 +41,26 @@ type Daemon struct { Signals chan os.Signal } +// Start the daemon. func (d *Daemon) Start(ctx context.Context) error { + if err := d.Queue.Create(); err != nil { + return err + } + defer func() { + if err := d.Queue.Delete(); err != nil { + log.WithError(err).Error("Failed to delete queue") + } + }() + + if err := d.Queue.Subscribe(); err != nil { + return err + } + defer func() { + if err := d.Queue.Unsubscribe(); err != nil { + log.WithError(err).Error("Failed to unsubscribe from sns topic") + } + }() + ch := make(chan *sqs.Message) go func() { diff --git a/main.go b/main.go index 05e1a27..2ccdbb5 100644 --- a/main.go +++ b/main.go @@ -75,16 +75,10 @@ func main() { instanceID = id } - sess := session.New() - queue, err := CreateQueue(sess, generateQueueName(instanceID), snsTopic) + sess, err := session.NewSession() if err != nil { - log.Fatal(err) + log.WithError(err).Fatal("Failed to create new session") } - defer func() { - if err = queue.Delete(); err != nil { - log.Fatalf("Failed to delete queue: %v", err) - } - }() sigs := make(chan os.Signal, 2) defer close(sigs) @@ -114,7 +108,7 @@ func main() { AutoScaling: autoscaling.New(sess), Handler: handler, Signals: sigs, - Queue: queue, + Queue: NewQueue(sess, generateQueueName(instanceID), snsTopic), } return daemon.Start(ctx) diff --git a/queue.go b/queue.go index 6f41839..e6cb68e 100644 --- a/queue.go +++ b/queue.go @@ -12,7 +12,9 @@ import ( "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sns" + "github.com/aws/aws-sdk-go/service/sns/snsiface" "github.com/aws/aws-sdk-go/service/sqs" + "github.com/aws/aws-sdk-go/service/sqs/sqsiface" ) const queuePolicy = ` @@ -38,69 +40,95 @@ const ( longPollingWaitTimeSeconds = 20 ) +// SQSClient for testing purposes (TODO: Gomock). +type SQSClient sqsiface.SQSAPI + +// SNSClient for testing purposes (TODO: Gomock). +type SNSClient snsiface.SNSAPI + +// Queue manages the SQS queue and SNS subscription. type Queue struct { - name string - url string - arn string - subscription string - session *session.Session + name string + url string + arn string + topicArn string + subscriptionArn string + + sqsClient SQSClient + snsClient SNSClient } -func CreateQueue(sess *session.Session, queueName string, topicARN string) (*Queue, error) { - sqsAPI := sqs.New(sess) - snsAPI := sns.New(sess) +// NewQueue returns a new... Queue. +func NewQueue(sess *session.Session, queueName, topicArn string) *Queue { + return &Queue{ + name: queueName, + topicArn: topicArn, + sqsClient: sqs.New(sess), + snsClient: sns.New(sess), + } +} - log.WithFields(log.Fields{"queue": queueName}).Debug("Creating sqs queue") - resp, err := sqsAPI.CreateQueue(&sqs.CreateQueueInput{ - QueueName: aws.String(queueName), +// Create the SQS queue. +func (q *Queue) Create() error { + log.WithFields(log.Fields{"queue": q.name}).Debug("Creating sqs queue") + out, err := q.sqsClient.CreateQueue(&sqs.CreateQueueInput{ + QueueName: aws.String(q.name), Attributes: map[string]*string{ - "Policy": aws.String(fmt.Sprintf(queuePolicy, topicARN)), + "Policy": aws.String(fmt.Sprintf(queuePolicy, q.topicArn)), "ReceiveMessageWaitTimeSeconds": aws.String(strconv.Itoa(longPollingWaitTimeSeconds)), }, }) if err != nil { - return nil, err + return err } + q.url = aws.StringValue(out.QueueUrl) + return nil +} - log.WithFields(log.Fields{"queue": queueName}).Debug("Looking up sqs queue url") - attrs, err := sqsAPI.GetQueueAttributes(&sqs.GetQueueAttributesInput{ - AttributeNames: aws.StringSlice([]string{"QueueArn"}), - QueueUrl: resp.QueueUrl, - }) - if err != nil { - return nil, err +// GetArn for the SQS queue. +func (q *Queue) getArn() (string, error) { + if q.arn == "" { + log.WithFields(log.Fields{"queue": q.name}).Debug("Looking up sqs queue arn") + out, err := q.sqsClient.GetQueueAttributes(&sqs.GetQueueAttributesInput{ + AttributeNames: aws.StringSlice([]string{"QueueArn"}), + QueueUrl: aws.String(q.url), + }) + if err != nil { + return "", err + } + arn, ok := out.Attributes["QueueArn"] + if !ok { + return "", errors.New("No attribute QueueArn") + } + q.arn = aws.StringValue(arn) } + return q.arn, nil +} - arn, ok := attrs.Attributes["QueueArn"] - if !ok { - return nil, errors.New("No attribute QueueArn") - } +// Subscribe the queue to an SNS topic +func (q *Queue) Subscribe() error { + log.WithFields(log.Fields{"queue": q.name, "topic": q.topicArn}).Debug("Subscribing queue to sns topic") - log.WithFields(log.Fields{"queue": queueName, "topic": topicARN}).Debug("Subscribing queue to sns topic") - subscr, err := snsAPI.Subscribe(&sns.SubscribeInput{ + arn, err := q.getArn() + if err != nil { + return err + } + out, err := q.snsClient.Subscribe(&sns.SubscribeInput{ + TopicArn: aws.String(q.topicArn), Protocol: aws.String("sqs"), - TopicArn: aws.String(topicARN), - Endpoint: arn, + Endpoint: aws.String(arn), }) if err != nil { - return nil, err + return err } - - return &Queue{ - name: queueName, - url: *resp.QueueUrl, - subscription: *subscr.SubscriptionArn, - arn: *arn, - session: sess, - }, nil + q.subscriptionArn = aws.StringValue(out.SubscriptionArn) + return nil } +// Receive a message from the SQS queue. func (q *Queue) Receive(ctx context.Context, ch chan *sqs.Message) error { - // Close channel before returning since this is the sending side. - defer close(ch) log.WithFields(log.Fields{"queueURL": q.url}).Debugf("Polling sqs for messages") - - sqsAPI := sqs.New(q.session) + defer close(ch) // Close channel before returning since this is the sending side. Loop: for { @@ -108,7 +136,7 @@ Loop: case <-ctx.Done(): break Loop default: - resp, err := sqsAPI.ReceiveMessageWithContext(ctx, &sqs.ReceiveMessageInput{ + out, err := q.sqsClient.ReceiveMessageWithContext(ctx, &sqs.ReceiveMessageInput{ QueueUrl: aws.String(q.url), MaxNumberOfMessages: aws.Int64(1), WaitTimeSeconds: aws.Int64(longPollingWaitTimeSeconds), @@ -121,8 +149,8 @@ Loop: } return err } - for _, m := range resp.Messages { - sqsAPI.DeleteMessageWithContext(ctx, &sqs.DeleteMessageInput{ + for _, m := range out.Messages { + q.sqsClient.DeleteMessageWithContext(ctx, &sqs.DeleteMessageInput{ QueueUrl: aws.String(q.url), ReceiptHandle: m.ReceiptHandle, }) @@ -133,21 +161,26 @@ Loop: return nil } -func (q *Queue) Delete() error { - sqsAPI := sqs.New(q.session) - snsAPI := sns.New(q.session) - - log.WithFields(log.Fields{"arn": q.subscription}).Debugf("Deleting sns subscription") - _, err := snsAPI.Unsubscribe(&sns.UnsubscribeInput{ - SubscriptionArn: aws.String(q.subscription), +// Unsubscribe the queue from the SNS topic. +func (q *Queue) Unsubscribe() error { + log.WithFields(log.Fields{"arn": q.subscriptionArn}).Debugf("Deleting sns subscription") + _, err := q.snsClient.Unsubscribe(&sns.UnsubscribeInput{ + SubscriptionArn: aws.String(q.subscriptionArn), }) - if err != nil { - return err - } + return err +} +// Delete the SQS queue. +func (q *Queue) Delete() error { log.WithFields(log.Fields{"url": q.url}).Debugf("Deleting sqs queue") - _, err = sqsAPI.DeleteQueue(&sqs.DeleteQueueInput{ + _, err := q.sqsClient.DeleteQueue(&sqs.DeleteQueueInput{ QueueUrl: aws.String(q.url), }) - return err + if err != nil { + // Ignore error if queue does not exist (which is what we want) + if e, ok := err.(awserr.Error); !ok || e.Code() != sqs.ErrCodeQueueDoesNotExist { + return err + } + } + return nil } diff --git a/vendor/github.com/aws/aws-sdk-go/service/sns/snsiface/interface.go b/vendor/github.com/aws/aws-sdk-go/service/sns/snsiface/interface.go new file mode 100644 index 0000000..9ef06d4 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/service/sns/snsiface/interface.go @@ -0,0 +1,199 @@ +// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. + +// Package snsiface provides an interface to enable mocking the Amazon Simple Notification Service service client +// for testing your code. +// +// It is important to note that this interface will have breaking changes +// when the service model is updated and adds new API operations, paginators, +// and waiters. +package snsiface + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" + "github.com/aws/aws-sdk-go/service/sns" +) + +// SNSAPI provides an interface to enable mocking the +// sns.SNS service client's API operation, +// paginators, and waiters. This make unit testing your code that calls out +// to the SDK's service client's calls easier. +// +// The best way to use this interface is so the SDK's service client's calls +// can be stubbed out for unit testing your code with the SDK without needing +// to inject custom request handlers into the SDK's request pipeline. +// +// // myFunc uses an SDK service client to make a request to +// // Amazon Simple Notification Service. +// func myFunc(svc snsiface.SNSAPI) bool { +// // Make svc.AddPermission request +// } +// +// func main() { +// sess := session.New() +// svc := sns.New(sess) +// +// myFunc(svc) +// } +// +// In your _test.go file: +// +// // Define a mock struct to be used in your unit tests of myFunc. +// type mockSNSClient struct { +// snsiface.SNSAPI +// } +// func (m *mockSNSClient) AddPermission(input *sns.AddPermissionInput) (*sns.AddPermissionOutput, error) { +// // mock response/functionality +// } +// +// func TestMyFunc(t *testing.T) { +// // Setup Test +// mockSvc := &mockSNSClient{} +// +// myfunc(mockSvc) +// +// // Verify myFunc's functionality +// } +// +// It is important to note that this interface will have breaking changes +// when the service model is updated and adds new API operations, paginators, +// and waiters. Its suggested to use the pattern above for testing, or using +// tooling to generate mocks to satisfy the interfaces. +type SNSAPI interface { + AddPermission(*sns.AddPermissionInput) (*sns.AddPermissionOutput, error) + AddPermissionWithContext(aws.Context, *sns.AddPermissionInput, ...request.Option) (*sns.AddPermissionOutput, error) + AddPermissionRequest(*sns.AddPermissionInput) (*request.Request, *sns.AddPermissionOutput) + + CheckIfPhoneNumberIsOptedOut(*sns.CheckIfPhoneNumberIsOptedOutInput) (*sns.CheckIfPhoneNumberIsOptedOutOutput, error) + CheckIfPhoneNumberIsOptedOutWithContext(aws.Context, *sns.CheckIfPhoneNumberIsOptedOutInput, ...request.Option) (*sns.CheckIfPhoneNumberIsOptedOutOutput, error) + CheckIfPhoneNumberIsOptedOutRequest(*sns.CheckIfPhoneNumberIsOptedOutInput) (*request.Request, *sns.CheckIfPhoneNumberIsOptedOutOutput) + + ConfirmSubscription(*sns.ConfirmSubscriptionInput) (*sns.ConfirmSubscriptionOutput, error) + ConfirmSubscriptionWithContext(aws.Context, *sns.ConfirmSubscriptionInput, ...request.Option) (*sns.ConfirmSubscriptionOutput, error) + ConfirmSubscriptionRequest(*sns.ConfirmSubscriptionInput) (*request.Request, *sns.ConfirmSubscriptionOutput) + + CreatePlatformApplication(*sns.CreatePlatformApplicationInput) (*sns.CreatePlatformApplicationOutput, error) + CreatePlatformApplicationWithContext(aws.Context, *sns.CreatePlatformApplicationInput, ...request.Option) (*sns.CreatePlatformApplicationOutput, error) + CreatePlatformApplicationRequest(*sns.CreatePlatformApplicationInput) (*request.Request, *sns.CreatePlatformApplicationOutput) + + CreatePlatformEndpoint(*sns.CreatePlatformEndpointInput) (*sns.CreatePlatformEndpointOutput, error) + CreatePlatformEndpointWithContext(aws.Context, *sns.CreatePlatformEndpointInput, ...request.Option) (*sns.CreatePlatformEndpointOutput, error) + CreatePlatformEndpointRequest(*sns.CreatePlatformEndpointInput) (*request.Request, *sns.CreatePlatformEndpointOutput) + + CreateTopic(*sns.CreateTopicInput) (*sns.CreateTopicOutput, error) + CreateTopicWithContext(aws.Context, *sns.CreateTopicInput, ...request.Option) (*sns.CreateTopicOutput, error) + CreateTopicRequest(*sns.CreateTopicInput) (*request.Request, *sns.CreateTopicOutput) + + DeleteEndpoint(*sns.DeleteEndpointInput) (*sns.DeleteEndpointOutput, error) + DeleteEndpointWithContext(aws.Context, *sns.DeleteEndpointInput, ...request.Option) (*sns.DeleteEndpointOutput, error) + DeleteEndpointRequest(*sns.DeleteEndpointInput) (*request.Request, *sns.DeleteEndpointOutput) + + DeletePlatformApplication(*sns.DeletePlatformApplicationInput) (*sns.DeletePlatformApplicationOutput, error) + DeletePlatformApplicationWithContext(aws.Context, *sns.DeletePlatformApplicationInput, ...request.Option) (*sns.DeletePlatformApplicationOutput, error) + DeletePlatformApplicationRequest(*sns.DeletePlatformApplicationInput) (*request.Request, *sns.DeletePlatformApplicationOutput) + + DeleteTopic(*sns.DeleteTopicInput) (*sns.DeleteTopicOutput, error) + DeleteTopicWithContext(aws.Context, *sns.DeleteTopicInput, ...request.Option) (*sns.DeleteTopicOutput, error) + DeleteTopicRequest(*sns.DeleteTopicInput) (*request.Request, *sns.DeleteTopicOutput) + + GetEndpointAttributes(*sns.GetEndpointAttributesInput) (*sns.GetEndpointAttributesOutput, error) + GetEndpointAttributesWithContext(aws.Context, *sns.GetEndpointAttributesInput, ...request.Option) (*sns.GetEndpointAttributesOutput, error) + GetEndpointAttributesRequest(*sns.GetEndpointAttributesInput) (*request.Request, *sns.GetEndpointAttributesOutput) + + GetPlatformApplicationAttributes(*sns.GetPlatformApplicationAttributesInput) (*sns.GetPlatformApplicationAttributesOutput, error) + GetPlatformApplicationAttributesWithContext(aws.Context, *sns.GetPlatformApplicationAttributesInput, ...request.Option) (*sns.GetPlatformApplicationAttributesOutput, error) + GetPlatformApplicationAttributesRequest(*sns.GetPlatformApplicationAttributesInput) (*request.Request, *sns.GetPlatformApplicationAttributesOutput) + + GetSMSAttributes(*sns.GetSMSAttributesInput) (*sns.GetSMSAttributesOutput, error) + GetSMSAttributesWithContext(aws.Context, *sns.GetSMSAttributesInput, ...request.Option) (*sns.GetSMSAttributesOutput, error) + GetSMSAttributesRequest(*sns.GetSMSAttributesInput) (*request.Request, *sns.GetSMSAttributesOutput) + + GetSubscriptionAttributes(*sns.GetSubscriptionAttributesInput) (*sns.GetSubscriptionAttributesOutput, error) + GetSubscriptionAttributesWithContext(aws.Context, *sns.GetSubscriptionAttributesInput, ...request.Option) (*sns.GetSubscriptionAttributesOutput, error) + GetSubscriptionAttributesRequest(*sns.GetSubscriptionAttributesInput) (*request.Request, *sns.GetSubscriptionAttributesOutput) + + GetTopicAttributes(*sns.GetTopicAttributesInput) (*sns.GetTopicAttributesOutput, error) + GetTopicAttributesWithContext(aws.Context, *sns.GetTopicAttributesInput, ...request.Option) (*sns.GetTopicAttributesOutput, error) + GetTopicAttributesRequest(*sns.GetTopicAttributesInput) (*request.Request, *sns.GetTopicAttributesOutput) + + ListEndpointsByPlatformApplication(*sns.ListEndpointsByPlatformApplicationInput) (*sns.ListEndpointsByPlatformApplicationOutput, error) + ListEndpointsByPlatformApplicationWithContext(aws.Context, *sns.ListEndpointsByPlatformApplicationInput, ...request.Option) (*sns.ListEndpointsByPlatformApplicationOutput, error) + ListEndpointsByPlatformApplicationRequest(*sns.ListEndpointsByPlatformApplicationInput) (*request.Request, *sns.ListEndpointsByPlatformApplicationOutput) + + ListEndpointsByPlatformApplicationPages(*sns.ListEndpointsByPlatformApplicationInput, func(*sns.ListEndpointsByPlatformApplicationOutput, bool) bool) error + ListEndpointsByPlatformApplicationPagesWithContext(aws.Context, *sns.ListEndpointsByPlatformApplicationInput, func(*sns.ListEndpointsByPlatformApplicationOutput, bool) bool, ...request.Option) error + + ListPhoneNumbersOptedOut(*sns.ListPhoneNumbersOptedOutInput) (*sns.ListPhoneNumbersOptedOutOutput, error) + ListPhoneNumbersOptedOutWithContext(aws.Context, *sns.ListPhoneNumbersOptedOutInput, ...request.Option) (*sns.ListPhoneNumbersOptedOutOutput, error) + ListPhoneNumbersOptedOutRequest(*sns.ListPhoneNumbersOptedOutInput) (*request.Request, *sns.ListPhoneNumbersOptedOutOutput) + + ListPlatformApplications(*sns.ListPlatformApplicationsInput) (*sns.ListPlatformApplicationsOutput, error) + ListPlatformApplicationsWithContext(aws.Context, *sns.ListPlatformApplicationsInput, ...request.Option) (*sns.ListPlatformApplicationsOutput, error) + ListPlatformApplicationsRequest(*sns.ListPlatformApplicationsInput) (*request.Request, *sns.ListPlatformApplicationsOutput) + + ListPlatformApplicationsPages(*sns.ListPlatformApplicationsInput, func(*sns.ListPlatformApplicationsOutput, bool) bool) error + ListPlatformApplicationsPagesWithContext(aws.Context, *sns.ListPlatformApplicationsInput, func(*sns.ListPlatformApplicationsOutput, bool) bool, ...request.Option) error + + ListSubscriptions(*sns.ListSubscriptionsInput) (*sns.ListSubscriptionsOutput, error) + ListSubscriptionsWithContext(aws.Context, *sns.ListSubscriptionsInput, ...request.Option) (*sns.ListSubscriptionsOutput, error) + ListSubscriptionsRequest(*sns.ListSubscriptionsInput) (*request.Request, *sns.ListSubscriptionsOutput) + + ListSubscriptionsPages(*sns.ListSubscriptionsInput, func(*sns.ListSubscriptionsOutput, bool) bool) error + ListSubscriptionsPagesWithContext(aws.Context, *sns.ListSubscriptionsInput, func(*sns.ListSubscriptionsOutput, bool) bool, ...request.Option) error + + ListSubscriptionsByTopic(*sns.ListSubscriptionsByTopicInput) (*sns.ListSubscriptionsByTopicOutput, error) + ListSubscriptionsByTopicWithContext(aws.Context, *sns.ListSubscriptionsByTopicInput, ...request.Option) (*sns.ListSubscriptionsByTopicOutput, error) + ListSubscriptionsByTopicRequest(*sns.ListSubscriptionsByTopicInput) (*request.Request, *sns.ListSubscriptionsByTopicOutput) + + ListSubscriptionsByTopicPages(*sns.ListSubscriptionsByTopicInput, func(*sns.ListSubscriptionsByTopicOutput, bool) bool) error + ListSubscriptionsByTopicPagesWithContext(aws.Context, *sns.ListSubscriptionsByTopicInput, func(*sns.ListSubscriptionsByTopicOutput, bool) bool, ...request.Option) error + + ListTopics(*sns.ListTopicsInput) (*sns.ListTopicsOutput, error) + ListTopicsWithContext(aws.Context, *sns.ListTopicsInput, ...request.Option) (*sns.ListTopicsOutput, error) + ListTopicsRequest(*sns.ListTopicsInput) (*request.Request, *sns.ListTopicsOutput) + + ListTopicsPages(*sns.ListTopicsInput, func(*sns.ListTopicsOutput, bool) bool) error + ListTopicsPagesWithContext(aws.Context, *sns.ListTopicsInput, func(*sns.ListTopicsOutput, bool) bool, ...request.Option) error + + OptInPhoneNumber(*sns.OptInPhoneNumberInput) (*sns.OptInPhoneNumberOutput, error) + OptInPhoneNumberWithContext(aws.Context, *sns.OptInPhoneNumberInput, ...request.Option) (*sns.OptInPhoneNumberOutput, error) + OptInPhoneNumberRequest(*sns.OptInPhoneNumberInput) (*request.Request, *sns.OptInPhoneNumberOutput) + + Publish(*sns.PublishInput) (*sns.PublishOutput, error) + PublishWithContext(aws.Context, *sns.PublishInput, ...request.Option) (*sns.PublishOutput, error) + PublishRequest(*sns.PublishInput) (*request.Request, *sns.PublishOutput) + + RemovePermission(*sns.RemovePermissionInput) (*sns.RemovePermissionOutput, error) + RemovePermissionWithContext(aws.Context, *sns.RemovePermissionInput, ...request.Option) (*sns.RemovePermissionOutput, error) + RemovePermissionRequest(*sns.RemovePermissionInput) (*request.Request, *sns.RemovePermissionOutput) + + SetEndpointAttributes(*sns.SetEndpointAttributesInput) (*sns.SetEndpointAttributesOutput, error) + SetEndpointAttributesWithContext(aws.Context, *sns.SetEndpointAttributesInput, ...request.Option) (*sns.SetEndpointAttributesOutput, error) + SetEndpointAttributesRequest(*sns.SetEndpointAttributesInput) (*request.Request, *sns.SetEndpointAttributesOutput) + + SetPlatformApplicationAttributes(*sns.SetPlatformApplicationAttributesInput) (*sns.SetPlatformApplicationAttributesOutput, error) + SetPlatformApplicationAttributesWithContext(aws.Context, *sns.SetPlatformApplicationAttributesInput, ...request.Option) (*sns.SetPlatformApplicationAttributesOutput, error) + SetPlatformApplicationAttributesRequest(*sns.SetPlatformApplicationAttributesInput) (*request.Request, *sns.SetPlatformApplicationAttributesOutput) + + SetSMSAttributes(*sns.SetSMSAttributesInput) (*sns.SetSMSAttributesOutput, error) + SetSMSAttributesWithContext(aws.Context, *sns.SetSMSAttributesInput, ...request.Option) (*sns.SetSMSAttributesOutput, error) + SetSMSAttributesRequest(*sns.SetSMSAttributesInput) (*request.Request, *sns.SetSMSAttributesOutput) + + SetSubscriptionAttributes(*sns.SetSubscriptionAttributesInput) (*sns.SetSubscriptionAttributesOutput, error) + SetSubscriptionAttributesWithContext(aws.Context, *sns.SetSubscriptionAttributesInput, ...request.Option) (*sns.SetSubscriptionAttributesOutput, error) + SetSubscriptionAttributesRequest(*sns.SetSubscriptionAttributesInput) (*request.Request, *sns.SetSubscriptionAttributesOutput) + + SetTopicAttributes(*sns.SetTopicAttributesInput) (*sns.SetTopicAttributesOutput, error) + SetTopicAttributesWithContext(aws.Context, *sns.SetTopicAttributesInput, ...request.Option) (*sns.SetTopicAttributesOutput, error) + SetTopicAttributesRequest(*sns.SetTopicAttributesInput) (*request.Request, *sns.SetTopicAttributesOutput) + + Subscribe(*sns.SubscribeInput) (*sns.SubscribeOutput, error) + SubscribeWithContext(aws.Context, *sns.SubscribeInput, ...request.Option) (*sns.SubscribeOutput, error) + SubscribeRequest(*sns.SubscribeInput) (*request.Request, *sns.SubscribeOutput) + + Unsubscribe(*sns.UnsubscribeInput) (*sns.UnsubscribeOutput, error) + UnsubscribeWithContext(aws.Context, *sns.UnsubscribeInput, ...request.Option) (*sns.UnsubscribeOutput, error) + UnsubscribeRequest(*sns.UnsubscribeInput) (*request.Request, *sns.UnsubscribeOutput) +} + +var _ SNSAPI = (*sns.SNS)(nil) diff --git a/vendor/github.com/aws/aws-sdk-go/service/sqs/sqsiface/interface.go b/vendor/github.com/aws/aws-sdk-go/service/sqs/sqsiface/interface.go new file mode 100644 index 0000000..c916894 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/service/sqs/sqsiface/interface.go @@ -0,0 +1,144 @@ +// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. + +// Package sqsiface provides an interface to enable mocking the Amazon Simple Queue Service service client +// for testing your code. +// +// It is important to note that this interface will have breaking changes +// when the service model is updated and adds new API operations, paginators, +// and waiters. +package sqsiface + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" + "github.com/aws/aws-sdk-go/service/sqs" +) + +// SQSAPI provides an interface to enable mocking the +// sqs.SQS service client's API operation, +// paginators, and waiters. This make unit testing your code that calls out +// to the SDK's service client's calls easier. +// +// The best way to use this interface is so the SDK's service client's calls +// can be stubbed out for unit testing your code with the SDK without needing +// to inject custom request handlers into the SDK's request pipeline. +// +// // myFunc uses an SDK service client to make a request to +// // Amazon Simple Queue Service. +// func myFunc(svc sqsiface.SQSAPI) bool { +// // Make svc.AddPermission request +// } +// +// func main() { +// sess := session.New() +// svc := sqs.New(sess) +// +// myFunc(svc) +// } +// +// In your _test.go file: +// +// // Define a mock struct to be used in your unit tests of myFunc. +// type mockSQSClient struct { +// sqsiface.SQSAPI +// } +// func (m *mockSQSClient) AddPermission(input *sqs.AddPermissionInput) (*sqs.AddPermissionOutput, error) { +// // mock response/functionality +// } +// +// func TestMyFunc(t *testing.T) { +// // Setup Test +// mockSvc := &mockSQSClient{} +// +// myfunc(mockSvc) +// +// // Verify myFunc's functionality +// } +// +// It is important to note that this interface will have breaking changes +// when the service model is updated and adds new API operations, paginators, +// and waiters. Its suggested to use the pattern above for testing, or using +// tooling to generate mocks to satisfy the interfaces. +type SQSAPI interface { + AddPermission(*sqs.AddPermissionInput) (*sqs.AddPermissionOutput, error) + AddPermissionWithContext(aws.Context, *sqs.AddPermissionInput, ...request.Option) (*sqs.AddPermissionOutput, error) + AddPermissionRequest(*sqs.AddPermissionInput) (*request.Request, *sqs.AddPermissionOutput) + + ChangeMessageVisibility(*sqs.ChangeMessageVisibilityInput) (*sqs.ChangeMessageVisibilityOutput, error) + ChangeMessageVisibilityWithContext(aws.Context, *sqs.ChangeMessageVisibilityInput, ...request.Option) (*sqs.ChangeMessageVisibilityOutput, error) + ChangeMessageVisibilityRequest(*sqs.ChangeMessageVisibilityInput) (*request.Request, *sqs.ChangeMessageVisibilityOutput) + + ChangeMessageVisibilityBatch(*sqs.ChangeMessageVisibilityBatchInput) (*sqs.ChangeMessageVisibilityBatchOutput, error) + ChangeMessageVisibilityBatchWithContext(aws.Context, *sqs.ChangeMessageVisibilityBatchInput, ...request.Option) (*sqs.ChangeMessageVisibilityBatchOutput, error) + ChangeMessageVisibilityBatchRequest(*sqs.ChangeMessageVisibilityBatchInput) (*request.Request, *sqs.ChangeMessageVisibilityBatchOutput) + + CreateQueue(*sqs.CreateQueueInput) (*sqs.CreateQueueOutput, error) + CreateQueueWithContext(aws.Context, *sqs.CreateQueueInput, ...request.Option) (*sqs.CreateQueueOutput, error) + CreateQueueRequest(*sqs.CreateQueueInput) (*request.Request, *sqs.CreateQueueOutput) + + DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error) + DeleteMessageWithContext(aws.Context, *sqs.DeleteMessageInput, ...request.Option) (*sqs.DeleteMessageOutput, error) + DeleteMessageRequest(*sqs.DeleteMessageInput) (*request.Request, *sqs.DeleteMessageOutput) + + DeleteMessageBatch(*sqs.DeleteMessageBatchInput) (*sqs.DeleteMessageBatchOutput, error) + DeleteMessageBatchWithContext(aws.Context, *sqs.DeleteMessageBatchInput, ...request.Option) (*sqs.DeleteMessageBatchOutput, error) + DeleteMessageBatchRequest(*sqs.DeleteMessageBatchInput) (*request.Request, *sqs.DeleteMessageBatchOutput) + + DeleteQueue(*sqs.DeleteQueueInput) (*sqs.DeleteQueueOutput, error) + DeleteQueueWithContext(aws.Context, *sqs.DeleteQueueInput, ...request.Option) (*sqs.DeleteQueueOutput, error) + DeleteQueueRequest(*sqs.DeleteQueueInput) (*request.Request, *sqs.DeleteQueueOutput) + + GetQueueAttributes(*sqs.GetQueueAttributesInput) (*sqs.GetQueueAttributesOutput, error) + GetQueueAttributesWithContext(aws.Context, *sqs.GetQueueAttributesInput, ...request.Option) (*sqs.GetQueueAttributesOutput, error) + GetQueueAttributesRequest(*sqs.GetQueueAttributesInput) (*request.Request, *sqs.GetQueueAttributesOutput) + + GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) + GetQueueUrlWithContext(aws.Context, *sqs.GetQueueUrlInput, ...request.Option) (*sqs.GetQueueUrlOutput, error) + GetQueueUrlRequest(*sqs.GetQueueUrlInput) (*request.Request, *sqs.GetQueueUrlOutput) + + ListDeadLetterSourceQueues(*sqs.ListDeadLetterSourceQueuesInput) (*sqs.ListDeadLetterSourceQueuesOutput, error) + ListDeadLetterSourceQueuesWithContext(aws.Context, *sqs.ListDeadLetterSourceQueuesInput, ...request.Option) (*sqs.ListDeadLetterSourceQueuesOutput, error) + ListDeadLetterSourceQueuesRequest(*sqs.ListDeadLetterSourceQueuesInput) (*request.Request, *sqs.ListDeadLetterSourceQueuesOutput) + + ListQueueTags(*sqs.ListQueueTagsInput) (*sqs.ListQueueTagsOutput, error) + ListQueueTagsWithContext(aws.Context, *sqs.ListQueueTagsInput, ...request.Option) (*sqs.ListQueueTagsOutput, error) + ListQueueTagsRequest(*sqs.ListQueueTagsInput) (*request.Request, *sqs.ListQueueTagsOutput) + + ListQueues(*sqs.ListQueuesInput) (*sqs.ListQueuesOutput, error) + ListQueuesWithContext(aws.Context, *sqs.ListQueuesInput, ...request.Option) (*sqs.ListQueuesOutput, error) + ListQueuesRequest(*sqs.ListQueuesInput) (*request.Request, *sqs.ListQueuesOutput) + + PurgeQueue(*sqs.PurgeQueueInput) (*sqs.PurgeQueueOutput, error) + PurgeQueueWithContext(aws.Context, *sqs.PurgeQueueInput, ...request.Option) (*sqs.PurgeQueueOutput, error) + PurgeQueueRequest(*sqs.PurgeQueueInput) (*request.Request, *sqs.PurgeQueueOutput) + + ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error) + ReceiveMessageWithContext(aws.Context, *sqs.ReceiveMessageInput, ...request.Option) (*sqs.ReceiveMessageOutput, error) + ReceiveMessageRequest(*sqs.ReceiveMessageInput) (*request.Request, *sqs.ReceiveMessageOutput) + + RemovePermission(*sqs.RemovePermissionInput) (*sqs.RemovePermissionOutput, error) + RemovePermissionWithContext(aws.Context, *sqs.RemovePermissionInput, ...request.Option) (*sqs.RemovePermissionOutput, error) + RemovePermissionRequest(*sqs.RemovePermissionInput) (*request.Request, *sqs.RemovePermissionOutput) + + SendMessage(*sqs.SendMessageInput) (*sqs.SendMessageOutput, error) + SendMessageWithContext(aws.Context, *sqs.SendMessageInput, ...request.Option) (*sqs.SendMessageOutput, error) + SendMessageRequest(*sqs.SendMessageInput) (*request.Request, *sqs.SendMessageOutput) + + SendMessageBatch(*sqs.SendMessageBatchInput) (*sqs.SendMessageBatchOutput, error) + SendMessageBatchWithContext(aws.Context, *sqs.SendMessageBatchInput, ...request.Option) (*sqs.SendMessageBatchOutput, error) + SendMessageBatchRequest(*sqs.SendMessageBatchInput) (*request.Request, *sqs.SendMessageBatchOutput) + + SetQueueAttributes(*sqs.SetQueueAttributesInput) (*sqs.SetQueueAttributesOutput, error) + SetQueueAttributesWithContext(aws.Context, *sqs.SetQueueAttributesInput, ...request.Option) (*sqs.SetQueueAttributesOutput, error) + SetQueueAttributesRequest(*sqs.SetQueueAttributesInput) (*request.Request, *sqs.SetQueueAttributesOutput) + + TagQueue(*sqs.TagQueueInput) (*sqs.TagQueueOutput, error) + TagQueueWithContext(aws.Context, *sqs.TagQueueInput, ...request.Option) (*sqs.TagQueueOutput, error) + TagQueueRequest(*sqs.TagQueueInput) (*request.Request, *sqs.TagQueueOutput) + + UntagQueue(*sqs.UntagQueueInput) (*sqs.UntagQueueOutput, error) + UntagQueueWithContext(aws.Context, *sqs.UntagQueueInput, ...request.Option) (*sqs.UntagQueueOutput, error) + UntagQueueRequest(*sqs.UntagQueueInput) (*request.Request, *sqs.UntagQueueOutput) +} + +var _ SQSAPI = (*sqs.SQS)(nil) diff --git a/vendor/vendor.json b/vendor/vendor.json index 3449ecb..c65e11f 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -224,12 +224,24 @@ "revision": "46ffe7480c9d567070fab0ed39912241bbc77449", "revisionTime": "2018-08-28T19:42:26Z" }, + { + "checksumSHA1": "dFjsVobwi3REhN6pyQgWuR23VRw=", + "path": "github.com/aws/aws-sdk-go/service/sns/snsiface", + "revision": "1c16cd01d7852416012413263c331ef3172c9ad1", + "revisionTime": "2018-07-31T20:06:58Z" + }, { "checksumSHA1": "ECIZck5xhocpUl8GeUAdeSnCgvg=", "path": "github.com/aws/aws-sdk-go/service/sqs", "revision": "46ffe7480c9d567070fab0ed39912241bbc77449", "revisionTime": "2018-08-28T19:42:26Z" }, + { + "checksumSHA1": "AisiBB02O+XJ/CPCBl4hD6xuXMs=", + "path": "github.com/aws/aws-sdk-go/service/sqs/sqsiface", + "revision": "1c16cd01d7852416012413263c331ef3172c9ad1", + "revisionTime": "2018-07-31T20:06:58Z" + }, { "checksumSHA1": "UhIVLDgQc19wjrPj8pP7Fu2UwWc=", "path": "github.com/aws/aws-sdk-go/service/sts",