driftctl/pkg/remote/aws/repository/sns_repository.go

35 lines
759 B
Go
Raw Normal View History

package repository
2021-02-02 12:02:53 +00:00
import (
"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"
)
type SNSRepository interface {
2021-02-02 12:02:53 +00:00
ListAllTopics() ([]*sns.Topic, error)
}
type snsRepositoryImpl struct {
client snsiface.SNSAPI
2021-02-02 12:02:53 +00:00
}
func NewSNSClient(session *session.Session) *snsRepositoryImpl {
return &snsRepositoryImpl{
2021-02-02 12:02:53 +00:00
sns.New(session),
}
}
func (r *snsRepositoryImpl) ListAllTopics() ([]*sns.Topic, error) {
2021-02-02 12:02:53 +00:00
var topics []*sns.Topic
input := &sns.ListTopicsInput{}
err := r.client.ListTopicsPages(input, func(res *sns.ListTopicsOutput, lastPage bool) bool {
2021-02-02 12:02:53 +00:00
topics = append(topics, res.Topics...)
return !lastPage
})
if err != nil {
return nil, err
}
return topics, nil
}