Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions controller/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ func buildProvider(

zoneNameFilter := endpoint.NewDomainFilter(cfg.ZoneNameFilter)
zoneIDFilter := provider.NewZoneIDFilter(cfg.ZoneIDFilter)
zoneTypeFilter := provider.NewZoneTypeFilter(cfg.AWSZoneType)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this below, since it was only used by the aws provider.

zoneTagFilter := provider.NewZoneTagFilter(cfg.AWSZoneTagFilter)

switch cfg.Provider {
case "akamai":
Expand All @@ -181,6 +179,10 @@ func buildProvider(
case "alibabacloud":
p, err = alibabacloud.NewAlibabaCloudProvider(cfg.AlibabaCloudConfigFile, domainFilter, zoneIDFilter, cfg.AlibabaCloudZoneType, cfg.DryRun)
case "aws":

zoneTypeFilter := provider.NewZoneTypeFilter(cfg.AWSZoneType)
zoneTagFilter := provider.NewZoneTagFilter(cfg.AWSZoneTagFilter)

configs := aws.CreateV2Configs(cfg)
clients := make(map[string]aws.Route53API, len(configs))
for profile, config := range configs {
Expand Down
16 changes: 15 additions & 1 deletion provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,22 @@ func (p *AWSProvider) zones(ctx context.Context) (map[string]*profiledZone, erro
if !p.zoneIDFilter.Match(*zone.Id) {
continue
}
var IsPublicZone = false

if !p.zoneTypeFilter.Match(zone) {
// 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 {
IsPublicZone = p.zoneTypeFilter.ZoneType == provider.ZoneTypePublic
}

switch p.zoneTypeFilter.ZoneType {
case provider.ZoneTypePublic:
IsPublicZone = !zone.Config.PrivateZone
case provider.ZoneTypePrivate:
IsPublicZone = zone.Config.PrivateZone
}

if !IsPublicZone && !p.zoneTypeFilter.Match(zone) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the p.zoneTypeFilter.Match(zone) is even necessary here?

continue
}

Expand Down
38 changes: 10 additions & 28 deletions provider/zone_type_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,38 @@

package provider

import (
route53types "github.com/aws/aws-sdk-go-v2/service/route53/types"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goal of this exercise is to get this out of the provider package.

)

const (
zoneTypePublic = "public"
zoneTypePrivate = "private"
ZoneTypePublic = "public"
ZoneTypePrivate = "private"
)

// ZoneTypeFilter holds a zone type to filter for.
type ZoneTypeFilter struct {
zoneType string
ZoneType string
}

// NewZoneTypeFilter returns a new ZoneTypeFilter given a zone type to filter for.
func NewZoneTypeFilter(zoneType string) ZoneTypeFilter {
return ZoneTypeFilter{zoneType: zoneType}
return ZoneTypeFilter{ZoneType: zoneType}
}

// Match checks whether a zone matches the zone type that's filtered for.
func (f ZoneTypeFilter) Match(rawZoneType interface{}) bool {
// An empty zone filter includes all hosted zones.
if f.zoneType == "" {
if f.ZoneType == "" {
return true
}

switch zoneType := rawZoneType.(type) {

Check failure on line 41 in provider/zone_type_filter.go

View workflow job for this annotation

GitHub Actions / Markdown and Go

singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
// Given a zone type we return true if the given zone matches this type.
case string:
switch f.zoneType {
case zoneTypePublic:
return zoneType == zoneTypePublic
case zoneTypePrivate:
return zoneType == zoneTypePrivate
}
case route53types.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 !zoneType.Config.PrivateZone
case zoneTypePrivate:
return zoneType.Config.PrivateZone
switch f.ZoneType {
case ZoneTypePublic:
return zoneType == ZoneTypePublic
case ZoneTypePrivate:
return zoneType == ZoneTypePrivate
}
}

// We return false on any other path, e.g. unknown zone type filter value.
return false
}
14 changes: 5 additions & 9 deletions provider/zone_type_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,32 @@ package provider
import (
"testing"

route53types "github.com/aws/aws-sdk-go-v2/service/route53/types"

"github.com/stretchr/testify/assert"
)

func TestZoneTypeFilterMatch(t *testing.T) {
publicZoneStr := "public"
privateZoneStr := "private"
publicZoneAWS := route53types.HostedZone{Config: &route53types.HostedZoneConfig{PrivateZone: false}}
privateZoneAWS := route53types.HostedZone{Config: &route53types.HostedZoneConfig{PrivateZone: true}}

for _, tc := range []struct {
zoneTypeFilter string
matches bool
zones []interface{}
}{
{
"", true, []interface{}{publicZoneStr, privateZoneStr, route53types.HostedZone{}},
"", true, []interface{}{publicZoneStr, privateZoneStr},
},
{
"public", true, []interface{}{publicZoneStr, publicZoneAWS, route53types.HostedZone{}},
"public", true, []interface{}{publicZoneStr},
},
{
"public", false, []interface{}{privateZoneStr, privateZoneAWS},
"public", false, []interface{}{privateZoneStr},
},
{
"private", true, []interface{}{privateZoneStr, privateZoneAWS},
"private", true, []interface{}{privateZoneStr},
},
{
"private", false, []interface{}{publicZoneStr, publicZoneAWS, route53types.HostedZone{}},
"private", false, []interface{}{publicZoneStr},
},
{
"unknown", false, []interface{}{publicZoneStr},
Expand Down
Loading