otc: select correct zone if multiple returned (#1292)

This commit is contained in:
Jakob 2020-11-19 19:36:49 +01:00 committed by GitHub
parent 3158518511
commit 95bae8c50d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -69,6 +69,7 @@ type endpoint struct {
type zoneItem struct {
ID string `json:"id"`
Name string `json:"name"`
}
type zonesResponse struct {
@ -182,15 +183,13 @@ func (d *DNSProvider) getZoneID(zone string) (string, error) {
return "", fmt.Errorf("zone %s not found", zone)
}
if len(zonesRes.Zones) > 1 {
return "", errors.New("to many zones found")
for _, z := range zonesRes.Zones {
if z.Name == zone {
return z.ID, nil
}
}
if zonesRes.Zones[0].ID == "" {
return "", errors.New("id not found")
}
return zonesRes.Zones[0].ID, nil
return "", fmt.Errorf("zone %s not found", zone)
}
func (d *DNSProvider) getRecordSetID(zoneID, fqdn string) (string, error) {

View file

@ -76,7 +76,8 @@ func (m *DNSServerMock) HandleListZonesSuccessfully() {
fmt.Fprintf(w, `{
"zones":[{
"id":"123123"
"id":"123123",
"name":"example.com."
}]}
`)
})