diff --git a/provider/aws/aws.go b/provider/aws/aws.go index 187ed0305..51bce1f43 100644 --- a/provider/aws/aws.go +++ b/provider/aws/aws.go @@ -241,7 +241,7 @@ func (p *AWSProvider) Zones(ctx context.Context) (map[string]*route53.HostedZone continue } - if !p.zoneTypeFilter.MatchAWS(zone) { + if !p.zoneTypeFilter.Match(zone) { continue } diff --git a/provider/zone_type_filter.go b/provider/zone_type_filter.go index 2a923b61c..14ceac0e8 100644 --- a/provider/zone_type_filter.go +++ b/provider/zone_type_filter.go @@ -37,43 +37,34 @@ func NewZoneTypeFilter(zoneType string) ZoneTypeFilter { } // Match checks whether a zone matches the zone type that's filtered for. -func (f ZoneTypeFilter) Match(visibility string) bool { +func (f ZoneTypeFilter) Match(rawZoneType interface{}) bool { // An empty zone filter includes all hosted zones. if f.zoneType == "" { return true } + switch zoneType := rawZoneType.(type) { // Given a zone type we return true if the given zone matches this type. - switch f.zoneType { - case zoneTypePublic: - return visibility == zoneTypePublic - case zoneTypePrivate: - return visibility == zoneTypePrivate - } - - // We return false on any other path, e.g. unknown zone type filter value. - return false -} - -// Match checks whether a zone matches the zone type that's filtered for. -func (f ZoneTypeFilter) MatchAWS(zone *route53.HostedZone) bool { - // An empty zone filter includes all hosted zones. - if f.zoneType == "" { - return true - } - - // If the zone has no config we assume it's a public zone since the config's field - // `PrivateZone` is false by default in go. - if zone.Config == nil { - return f.zoneType == zoneTypePublic - } - - // Given a zone type we return true if the given zone matches this type. - switch f.zoneType { - case zoneTypePublic: - return !aws.BoolValue(zone.Config.PrivateZone) - case zoneTypePrivate: - return aws.BoolValue(zone.Config.PrivateZone) + case string: + switch f.zoneType { + case zoneTypePublic: + return zoneType == zoneTypePublic + case zoneTypePrivate: + return zoneType == zoneTypePrivate + } + case *route53.HostedZone: + // If the zone has no config we assume it's a public zone since the config's field + // `PrivateZone` is false by default in go. + if zoneType.Config == nil { + return f.zoneType == zoneTypePublic + } + + switch f.zoneType { + case zoneTypePublic: + return !aws.BoolValue(zoneType.Config.PrivateZone) + case zoneTypePrivate: + return aws.BoolValue(zoneType.Config.PrivateZone) + } } // We return false on any other path, e.g. unknown zone type filter value. diff --git a/provider/zone_type_filter_test.go b/provider/zone_type_filter_test.go index 629934e8f..d2297aef8 100644 --- a/provider/zone_type_filter_test.go +++ b/provider/zone_type_filter_test.go @@ -66,7 +66,7 @@ func TestZoneTypeFilterMatchAWS(t *testing.T) { }, } { zoneTypeFilter := NewZoneTypeFilter(tc.zoneTypeFilter) - assert.Equal(t, tc.matches, zoneTypeFilter.MatchAWS(tc.zone)) + assert.Equal(t, tc.matches, zoneTypeFilter.Match(tc.zone)) } }