sigs.k8s.io/external-dns@v0.14.1/provider/zone_id_filter.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package provider
    18  
    19  import "strings"
    20  
    21  // ZoneIDFilter holds a list of zone ids to filter by
    22  type ZoneIDFilter struct {
    23  	ZoneIDs []string
    24  }
    25  
    26  // NewZoneIDFilter returns a new ZoneIDFilter given a list of zone ids
    27  func NewZoneIDFilter(zoneIDs []string) ZoneIDFilter {
    28  	return ZoneIDFilter{zoneIDs}
    29  }
    30  
    31  // Match checks whether a zone matches one of the provided zone ids
    32  func (f ZoneIDFilter) Match(zoneID string) bool {
    33  	// An empty filter includes all zones.
    34  	if len(f.ZoneIDs) == 0 {
    35  		return true
    36  	}
    37  	if len(f.ZoneIDs) == 1 && f.ZoneIDs[0] == "" {
    38  		return true
    39  	}
    40  
    41  	for _, id := range f.ZoneIDs {
    42  		if strings.HasSuffix(zoneID, id) {
    43  			return true
    44  		}
    45  	}
    46  
    47  	return false
    48  }
    49  
    50  // IsConfigured returns true if DomainFilter is configured, false otherwise
    51  func (f ZoneIDFilter) IsConfigured() bool {
    52  	if len(f.ZoneIDs) == 1 {
    53  		return f.ZoneIDs[0] != ""
    54  	}
    55  	return len(f.ZoneIDs) > 0
    56  }