From 336c7062bd85ca8b7fa21b6a6d2996e7f2a2398c Mon Sep 17 00:00:00 2001 From: sundowndev Date: Tue, 6 Jul 2021 11:31:51 +0200 Subject: [PATCH] refactor: simplify code --- pkg/remote/aws/route53_record_enumerator.go | 22 ++++----------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/pkg/remote/aws/route53_record_enumerator.go b/pkg/remote/aws/route53_record_enumerator.go index 859b2cc7..9f861065 100644 --- a/pkg/remote/aws/route53_record_enumerator.go +++ b/pkg/remote/aws/route53_record_enumerator.go @@ -29,15 +29,15 @@ func (e *Route53RecordEnumerator) SupportedType() resource.ResourceType { func (e *Route53RecordEnumerator) Enumerate() ([]resource.Resource, error) { - zones, err := e.listZones() + zones, err := e.client.ListAllZones() if err != nil { return nil, remoteerror.NewResourceEnumerationErrorWithType(err, resourceaws.AwsRoute53RecordResourceType, resourceaws.AwsRoute53ZoneResourceType) } results := make([]resource.Resource, len(zones)) - for _, zone := range zones { - records, err := e.listRecordsForZone(zone[0], zone[1]) + for _, hostedZone := range zones { + records, err := e.listRecordsForZone(strings.TrimPrefix(*hostedZone.Id, "/hostedzone/")) if err != nil { return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsRoute53RecordResourceType) } @@ -48,21 +48,7 @@ func (e *Route53RecordEnumerator) Enumerate() ([]resource.Resource, error) { return results, err } -func (e *Route53RecordEnumerator) listZones() ([][2]string, error) { - results := make([][2]string, 0) - zones, err := e.client.ListAllZones() - if err != nil { - return nil, err - } - - for _, hostedZone := range zones { - results = append(results, [2]string{strings.TrimPrefix(*hostedZone.Id, "/hostedzone/"), *hostedZone.Name}) - } - - return results, nil -} - -func (e *Route53RecordEnumerator) listRecordsForZone(zoneId string, _ string) ([]resource.Resource, error) { +func (e *Route53RecordEnumerator) listRecordsForZone(zoneId string) ([]resource.Resource, error) { records, err := e.client.ListRecordsForZone(zoneId) if err != nil {