Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

CLOUD-1043: Remove Topics and acknowledged subscriptions #16

Merged
merged 1 commit into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions resources/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/sns"
)

func GetListers(sess *session.Session) []ResourceLister {
Expand All @@ -28,6 +29,7 @@ func GetListers(sess *session.Session) []ResourceLister {
rds = RDSNuke{rds.New(sess)}
route53 = Route53Nuke{route53.New(sess)}
s3 = S3Nuke{s3.New(sess)}
sns = SNSNuke{sns.New(sess)}
)

return []ResourceLister{
Expand Down Expand Up @@ -77,5 +79,7 @@ func GetListers(sess *session.Session) []ResourceLister {
route53.ListResourceRecords,
s3.ListBuckets,
s3.ListObjects,
sns.ListSubscriptions,
sns.ListTopics,
}
}
43 changes: 43 additions & 0 deletions resources/sns-subscriptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package resources

import (
"fmt"

"github.com/aws/aws-sdk-go/service/sns"
)

func (n *SNSNuke) ListSubscriptions() ([]Resource, error) {
resp, err := n.Service.ListSubscriptions(nil)
if err != nil {
return nil, err
}
resources := make([]Resource, 0)
for _, subscription := range resp.Subscriptions {
if *subscription.SubscriptionArn != "PendingConfirmation" {
resources = append(resources, &SNSSubscription{
svc: n.Service,
id: subscription.SubscriptionArn,
name: subscription.Owner,
})
}

}
return resources, nil
}

type SNSSubscription struct {
svc *sns.SNS
id *string
name *string
}

func (subs *SNSSubscription) Remove() error {
_, err := subs.svc.Unsubscribe(&sns.UnsubscribeInput{
SubscriptionArn: subs.id,
})
return err
}

func (subs *SNSSubscription) String() string {
return fmt.Sprintf("Owner: %s ARN: %s", *subs.name, *subs.id)
}
38 changes: 38 additions & 0 deletions resources/sns-topics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package resources

import (
"fmt"

"github.com/aws/aws-sdk-go/service/sns"
)

func (n *SNSNuke) ListTopics() ([]Resource, error) {
resp, err := n.Service.ListTopics(nil)
if err != nil {
return nil, err
}
resources := make([]Resource, 0)
for _, topic := range resp.Topics {
resources = append(resources, &SNSTopic{
svc: n.Service,
id: topic.TopicArn,
})
}
return resources, nil
}

type SNSTopic struct {
svc *sns.SNS
id *string
}

func (topic *SNSTopic) Remove() error {
_, err := topic.svc.DeleteTopic(&sns.DeleteTopicInput{
TopicArn: topic.id,
})
return err
}

func (topic *SNSTopic) String() string {
return fmt.Sprintf("TopicARN: %s", *topic.id)
}
5 changes: 5 additions & 0 deletions resources/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/sns"
)

type AutoScalingNuke struct {
Expand Down Expand Up @@ -57,3 +58,7 @@ type Route53Nuke struct {
type S3Nuke struct {
Service *s3.S3
}

type SNSNuke struct {
Service *sns.SNS
}