Skip to content

Commit

Permalink
Merge pull request #12 from nustiueudinastea/fix-record-name
Browse files Browse the repository at this point in the history
Preserve original record name and don't add a "." suffix
  • Loading branch information
obynio authored Jan 25, 2024
2 parents dcd0274 + 559bd19 commit 829a16e
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
p.mutex.Lock()
defer p.mutex.Unlock()

// Append a dot to get the absolute record name.
recAbsoluteName := record.Name + "."

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, recAbsoluteName, record.Type), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -49,7 +46,7 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
newGandiRecord := gandiRecord{
RRSetTTL: int(record.TTL.Seconds()),
RRSetType: record.Type,
RRSetName: recAbsoluteName,
RRSetName: record.Name,
RRSetValues: recValues,
}

Expand All @@ -59,7 +56,7 @@ func (p *Provider) setRecord(ctx context.Context, zone string, record libdns.Rec
}

// we update existing record or create a new record if it does not exist yet
req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, recAbsoluteName, record.Type), bytes.NewReader(raw))
req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), bytes.NewReader(raw))
if err != nil {
return err
}
Expand All @@ -75,10 +72,7 @@ func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.
p.mutex.Lock()
defer p.mutex.Unlock()

// Append a dot to get the absolute record name.
recAbsoluteName := record.Name + "."

req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, recAbsoluteName, record.Type), nil)
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
if err != nil {
return err
}
Expand All @@ -104,15 +98,15 @@ func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.
return err
}

req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, recAbsoluteName, record.Type), bytes.NewReader(raw))
req, err = http.NewRequestWithContext(ctx, "PUT", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), bytes.NewReader(raw))
} else {
// if there is only one entry, we make sure that the value to delete is matching the one we found
// otherwise we may delete the wrong record
if strings.Trim(rec.RRSetValues[0], "\"") != record.Value {
return fmt.Errorf("LiveDNS returned a %v (%v)", http.StatusNotFound, "Can't find such a DNS value")
}

req, err = http.NewRequestWithContext(ctx, "DELETE", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, recAbsoluteName, record.Type), nil)
req, err = http.NewRequestWithContext(ctx, "DELETE", fmt.Sprintf("%s/%s/%s", domain.DomainRecordsHref, record.Name, record.Type), nil)
}

// we check if NewRequestWithContext threw an error
Expand Down

0 comments on commit 829a16e

Please sign in to comment.