@@ -85,16 +85,12 @@ func (n NS1DomainService) ListZones() ([]*dns.Zone, *http.Response, error) {
8585
8686// NS1Config passes cli args to the NS1Provider
8787type NS1Config struct {
88- DomainFilter * endpoint.DomainFilter
89- ZoneIDFilter provider.ZoneIDFilter
90- NS1Endpoint string
91- NS1IgnoreSSL bool
92- DryRun bool
93- MinTTLSeconds int
94- // Optional: map a zone FQDN (or suffix) to the NS1 zone handle/ID to use
95- // when looking up that zone. Keys/values are case-insensitive;
96- // trailing dots on keys are ignored.
97- // e.g. map[string]string{"example.com":"corp-prod-zone","dev.example.com":"dev-view-handle"}
88+ DomainFilter * endpoint.DomainFilter
89+ ZoneIDFilter provider.ZoneIDFilter
90+ NS1Endpoint string
91+ NS1IgnoreSSL bool
92+ DryRun bool
93+ MinTTLSeconds int
9894 ZoneHandleOverrides map [string ]string
9995}
10096
@@ -164,7 +160,7 @@ func (p *NS1Provider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
164160 for _ , zone := range zones {
165161 // TODO handle Header Codes
166162 // Prefer lookup via handle/ID if an override exists; fall back to FQDN.
167- lookup := p .zoneLookupKeyFor (zone .Zone )
163+ lookup := p .longestMatch (zone .Zone )
168164 zoneData , _ , err := p .client .GetZone (lookup )
169165 if err != nil {
170166 if lookup != strings .TrimSuffix (zone .Zone , "." ) {
@@ -325,13 +321,17 @@ func normalizeOverrides(m map[string]string) map[string]string {
325321 if len (m ) == 0 {
326322 return map [string ]string {}
327323 }
328- out := make (map [string ]string , len ( m ) )
324+ out := make (map [string ]string )
329325 for k , v := range m {
330326 kk := strings .TrimSuffix (strings .ToLower (strings .TrimSpace (k )), "." )
331327 vv := strings .ToLower (strings .TrimSpace (v ))
332- if kk != "" && vv != "" {
333- out [kk ] = vv
328+
329+ if kk == "" || vv == "" {
330+ log .Debugf ("Encounted empty string for zone handle override: key=%s, value=%s" , kk , vv )
331+ continue
334332 }
333+
334+ out [kk ] = vv
335335 }
336336 return out
337337}
@@ -359,7 +359,7 @@ func (p *NS1Provider) ns1ChangesByZone(zones []*dns.Zone, changeSets []*ns1Chang
359359
360360 // replace zone FQDN with zone handle if FQDN is overridden
361361 for k , v := range changes {
362- writeKey := p .zoneLookupKeyFor (k )
362+ writeKey := p .longestMatch (k )
363363
364364 if writeKey != k {
365365 changes [writeKey ] = v
@@ -370,16 +370,16 @@ func (p *NS1Provider) ns1ChangesByZone(zones []*dns.Zone, changeSets []*ns1Chang
370370 return changes
371371}
372372
373- // zoneLookupKeyFor returns the preferred key to pass to GetZone:
373+ // longestMatch returns the preferred key to pass to GetZone:
374374// if an override exists for fqdn (or a more specific suffix), return its mapped handle/ID;
375375// otherwise return the normalized FQDN.
376- func (p * NS1Provider ) zoneLookupKeyFor (fqdn string ) string {
376+ func (p * NS1Provider ) longestMatch (fqdn string ) string {
377377 name := strings .TrimSuffix (strings .ToLower (strings .TrimSpace (fqdn )), "." )
378378 bestKey := ""
379379 for k := range p .zoneHandleOverrides {
380380 if name == k || strings .HasSuffix (name , "." + k ) {
381381 if len (k ) > len (bestKey ) {
382- bestKey = k // longest (most specific) match wins
382+ bestKey = k
383383 }
384384 }
385385 }
0 commit comments