Skip to content
Snippets Groups Projects
Commit 1901c414 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

Present(): Search existing record and only create if none exists

parent 5bc39b92
No related branches found
No related tags found
No related merge requests found
Pipeline #4184 passed
......@@ -39,14 +39,30 @@ func (s *solver) Present(ch *whapi.ChallengeRequest) error {
txt := fmt.Sprintf(`%s IN TXT "%s"`, ch.ResolvedFQDN, ch.Key)
record, err := client.CreateRecord(txt)
search := ch.ResolvedFQDN + " *"
records, err := client.ListRecords(nil, &search)
if err != nil {
klog.Error(err)
return err
}
var record rwthdns.Record
if len(records) == 0 {
record, err = client.CreateRecord(txt)
} else if len(records) == 1 {
record, err = client.UpdateRecord(records[0].Id, txt)
} else {
err = fmt.Errorf("More than one search result for %s", ch.ResolvedFQDN)
}
klog.V(2).Infof("record %+v", record)
if err != nil {
klog.Error(err)
return err
}
klog.V(2).Infof("record %+v", record)
zone, err := client.DeployZone(record.ZoneId)
klog.V(2).Infof("deployed zone %+v", zone)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment