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
1 change: 1 addition & 0 deletions client-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func (p *Provider) deleteCloudDNSRecord(ctx context.Context, zone, name, recordT
if err := p.newService(ctx); err != nil {
return nil, err
}

fullName := libdns.AbsoluteName(name, zone)
gcdZone, err := p.getCloudDNSZone(zone)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion client-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func (p *Provider) getCloudDNSRecord(ctx context.Context, zone, name, recordType
if err := p.newService(ctx); err != nil {
return nil, err
}

gcdZone, err := p.getCloudDNSZone(zone)
if err != nil {
return nil, err
}
fullName := libdns.AbsoluteName(name, zone)
fullName := normalizeHost(libdns.AbsoluteName(name, zone))
rrs, err := p.service.ResourceRecordSets.Get(p.Project, gcdZone, fullName, recordType).Context(ctx).Do()
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions client-post.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (p *Provider) postCloudDNSRecord(ctx context.Context, zone string, recordsT
if err := p.newService(ctx); err != nil {
return nil, err
}
zone = normalizeZone(zone)
gcdZone, err := p.getCloudDNSZone(zone)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (p *Provider) newService(ctx context.Context) error {
// getCloudDNSZone will return the Google Cloud DNS zone name for the specified zone. The data is cached
// for five minutes to avoid repeated calls to the GCP API servers.
func (p *Provider) getCloudDNSZone(zone string) (string, error) {
zone = normalizeZone(zone)
if p.zoneMap == nil || time.Since(p.zoneMapLastUpdated) > zoneMapTTL {
p.zoneMap = make(map[string]string)
zonesLister := p.service.ManagedZones.List(p.Project)
Expand Down
25 changes: 23 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ func (l libdnsRecords) hasRecord(record libdns.Record) bool {
}
return false
}

func contains(arr []string, value string) bool {
for _, v := range arr {
if v == value {
return true
}
}
return false
}
// doesNotHaveRecords returns true if this set of records does not contain the specified
// record. Only the name, type, and value are compared; the TTL is ignored.
func (l libdnsRecords) doesNotHaveRecord(record libdns.Record) bool {
Expand All @@ -64,7 +71,9 @@ func (l libdnsRecords) prepValuesForCloudDNS() []string {
//ensure we quote a value with spaces but do not double quote
value = fmt.Sprintf(`"%s"`, strings.Trim(value, `"`))
}
values = append(values, value)
if !contains(values, value) {
values = append(values, value)
}

}
return values
Expand All @@ -87,3 +96,15 @@ func convertToLibDNS(googleRecord *dns.ResourceRecordSet, zone string) libdnsRec
}
return records
}
func normalizeZone(zone string) string {
if zone[len(zone)-1:len(zone)] == "." {
return zone
}
return zone + "."
}
func normalizeHost(host string) string {
if host[len(host)-1:len(host)] == "." {
return host[:len(host)-1]
}
return host
}