From 95bae8c50d38739276ebc0629b66157c8a190444 Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 19 Nov 2020 19:36:49 +0100 Subject: [PATCH] otc: select correct zone if multiple returned (#1292) --- providers/dns/otc/client.go | 15 +++++++-------- providers/dns/otc/mock_test.go | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/providers/dns/otc/client.go b/providers/dns/otc/client.go index 86e22afe..ce8a3a9f 100644 --- a/providers/dns/otc/client.go +++ b/providers/dns/otc/client.go @@ -68,7 +68,8 @@ type endpoint struct { } type zoneItem struct { - ID string `json:"id"` + 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) { diff --git a/providers/dns/otc/mock_test.go b/providers/dns/otc/mock_test.go index 8340b250..9a8ad4e3 100644 --- a/providers/dns/otc/mock_test.go +++ b/providers/dns/otc/mock_test.go @@ -76,7 +76,8 @@ func (m *DNSServerMock) HandleListZonesSuccessfully() { fmt.Fprintf(w, `{ "zones":[{ - "id":"123123" + "id":"123123", + "name":"example.com." }]} `) })