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

35 lines
812 B
Go
Raw Normal View History

2021-02-11 11:21:49 +00:00
package repository
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
)
type DynamoDBRepository interface {
ListAllTables() ([]*string, error)
}
type dynamoDBRepository struct {
client dynamodbiface.DynamoDBAPI
}
func NewDynamoDBRepository(session *session.Session) *dynamoDBRepository {
return &dynamoDBRepository{
dynamodb.New(session),
}
}
func (r *dynamoDBRepository) ListAllTables() ([]*string, error) {
var tables []*string
input := &dynamodb.ListTablesInput{}
err := r.client.ListTablesPages(input, func(res *dynamodb.ListTablesOutput, lastPage bool) bool {
tables = append(tables, res.TableNames...)
return !lastPage
})
if err != nil {
return nil, err
}
return tables, nil
}