mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 09:36:58 +02:00
Simplify DomainFilterInterface
This commit is contained in:
parent
7efecc711f
commit
d1fb3423c4
@ -24,41 +24,22 @@ import (
|
||||
// DomainFilterInterface defines the interface to select matching domains for a specific provider or runtime
|
||||
type DomainFilterInterface interface {
|
||||
Match(domain string) bool
|
||||
IsConfigured() bool
|
||||
}
|
||||
|
||||
type MatchAllDomainFilters []DomainFilterInterface
|
||||
|
||||
func (f MatchAllDomainFilters) Match(domain string) bool {
|
||||
if !f.IsConfigured() {
|
||||
return true
|
||||
}
|
||||
for _, filter := range f {
|
||||
if filter == nil {
|
||||
continue
|
||||
}
|
||||
if filter.IsConfigured() && !filter.Match(domain) {
|
||||
if !filter.Match(domain) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (f MatchAllDomainFilters) IsConfigured() bool {
|
||||
if f == nil {
|
||||
return false
|
||||
}
|
||||
for _, filter := range f {
|
||||
if filter == nil {
|
||||
continue
|
||||
}
|
||||
if filter.IsConfigured() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return len(f) > 0
|
||||
}
|
||||
|
||||
// DomainFilter holds a lists of valid domain names
|
||||
type DomainFilter struct {
|
||||
// Filters define what domains to match
|
||||
|
@ -199,7 +199,7 @@ func (p AkamaiProvider) fetchZones() (akamaiZones, error) {
|
||||
}
|
||||
|
||||
for _, zone := range resp.Zones {
|
||||
if p.domainFilter.Match(zone.Zone) || !p.domainFilter.IsConfigured() {
|
||||
if p.domainFilter.Match(zone.Zone) {
|
||||
filteredZones.Zones = append(filteredZones.Zones, akamaiZone{ContractID: zone.ContractId, Zone: zone.Zone})
|
||||
log.Debugf("Fetched zone: '%s' (ZoneID: %s)", zone.Zone, zone.ContractId)
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func (p *piholeClient) listRecords(ctx context.Context, rtype string) ([]*endpoi
|
||||
for _, rec := range data {
|
||||
name := rec[0]
|
||||
target := rec[1]
|
||||
if p.cfg.DomainFilter.IsConfigured() && !p.cfg.DomainFilter.Match(name) {
|
||||
if !p.cfg.DomainFilter.Match(name) {
|
||||
log.Debugf("Skipping %s that does not match domain filter", name)
|
||||
continue
|
||||
}
|
||||
@ -195,7 +195,7 @@ type actionResponse struct {
|
||||
}
|
||||
|
||||
func (p *piholeClient) apply(ctx context.Context, action string, ep *endpoint.Endpoint) error {
|
||||
if p.cfg.DomainFilter.IsConfigured() && !p.cfg.DomainFilter.Match(ep.DNSName) {
|
||||
if !p.cfg.DomainFilter.Match(ep.DNSName) {
|
||||
log.Debugf("Skipping %s %s that does not match domain filter", action, ep.DNSName)
|
||||
return nil
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func (p *TencentCloudProvider) getPrivateZones() ([]*privatedns.PrivateZone, err
|
||||
|
||||
privateZonesFilter := make([]*privatedns.PrivateZone, 0)
|
||||
for _, privateZone := range privateZones {
|
||||
if p.domainFilter.IsConfigured() && !p.domainFilter.Match(*privateZone.Domain) {
|
||||
if !p.domainFilter.Match(*privateZone.Domain) {
|
||||
continue
|
||||
}
|
||||
privateZonesFilter = append(privateZonesFilter, privateZone)
|
||||
|
@ -34,6 +34,9 @@ func (f ZoneIDFilter) Match(zoneID string) bool {
|
||||
if len(f.ZoneIDs) == 0 {
|
||||
return true
|
||||
}
|
||||
if len(f.ZoneIDs) == 1 && f.ZoneIDs[0] == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, id := range f.ZoneIDs {
|
||||
if strings.HasSuffix(zoneID, id) {
|
||||
|
Loading…
Reference in New Issue
Block a user