exoscale: simplify record creation (#2179)

This commit is contained in:
Ludovic Fernandez 2024-05-07 12:30:44 +02:00 committed by GitHub
parent acd338259d
commit f6d1413a3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -127,12 +127,6 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("exoscale: zone %q not found", zoneName) return fmt.Errorf("exoscale: zone %q not found", zoneName)
} }
recordID, err := d.findExistingRecordID(deref(zone.ID), recordName)
if err != nil {
return fmt.Errorf("exoscale: %w", err)
}
if recordID == "" {
record := egoscale.DNSDomainRecord{ record := egoscale.DNSDomainRecord{
Name: pointer(recordName), Name: pointer(recordName),
TTL: pointer(d.config.TTL), TTL: pointer(d.config.TTL),
@ -145,22 +139,6 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("exoscale: error while creating DNS record: %w", err) return fmt.Errorf("exoscale: error while creating DNS record: %w", err)
} }
return nil
}
record := egoscale.DNSDomainRecord{
ID: pointer(recordID),
Name: pointer(recordName),
TTL: pointer(d.config.TTL),
Content: pointer(info.Value),
Type: pointer("TXT"),
}
err = d.client.UpdateDNSDomainRecord(ctx, d.apiZone, deref(zone.ID), &record)
if err != nil {
return fmt.Errorf("exoscale: error while updating DNS record: %w", err)
}
return nil return nil
} }
@ -182,7 +160,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("exoscale: zone %q not found", zoneName) return fmt.Errorf("exoscale: zone %q not found", zoneName)
} }
recordID, err := d.findExistingRecordID(deref(zone.ID), recordName) recordID, err := d.findExistingRecordID(deref(zone.ID), recordName, info.Value)
if err != nil { if err != nil {
return err return err
} }
@ -224,7 +202,7 @@ func (d *DNSProvider) findExistingZone(zoneName string) (*egoscale.DNSDomain, er
// findExistingRecordID Query Exoscale to find an existing record for this name. // findExistingRecordID Query Exoscale to find an existing record for this name.
// Returns empty result if no record could be found. // Returns empty result if no record could be found.
func (d *DNSProvider) findExistingRecordID(zoneID, recordName string) (string, error) { func (d *DNSProvider) findExistingRecordID(zoneID, recordName, value string) (string, error) {
ctx := context.Background() ctx := context.Background()
records, err := d.client.ListDNSDomainRecords(ctx, d.apiZone, zoneID) records, err := d.client.ListDNSDomainRecords(ctx, d.apiZone, zoneID)
@ -233,8 +211,7 @@ func (d *DNSProvider) findExistingRecordID(zoneID, recordName string) (string, e
} }
for _, record := range records { for _, record := range records {
if deref(record.Name) == recordName && if deref(record.Name) == recordName && deref(record.Type) == "TXT" && deref(record.Content) == value {
deref(record.Type) == "TXT" {
return deref(record.ID), nil return deref(record.ID), nil
} }
} }