driftctl/pkg/remote/aws/route53_zone_enumerator.go

51 lines
1.2 KiB
Go
Raw Normal View History

2021-07-05 15:27:47 +00:00
package aws
import (
"strings"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws"
)
type Route53ZoneSupplier struct {
client repository.Route53Repository
factory resource.ResourceFactory
}
func NewRoute53ZoneEnumerator(repo repository.Route53Repository, factory resource.ResourceFactory) *Route53ZoneSupplier {
return &Route53ZoneSupplier{
repo,
factory,
}
}
func (e *Route53ZoneSupplier) SupportedType() resource.ResourceType {
return resourceaws.AwsRoute53ZoneResourceType
}
func (e *Route53ZoneSupplier) Enumerate() ([]resource.Resource, error) {
zones, err := e.client.ListAllZones()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, string(e.SupportedType()))
2021-07-05 15:27:47 +00:00
}
results := make([]resource.Resource, len(zones))
for _, hostedZone := range zones {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
2021-07-05 15:43:23 +00:00
strings.TrimPrefix(*hostedZone.Id, "/hostedzone/"),
2021-07-05 15:27:47 +00:00
map[string]interface{}{},
),
)
}
return results, err
}