rackspace: change zone ID to string (#1508)

This commit is contained in:
Chris Hepner 2021-10-18 10:11:07 -07:00 committed by GitHub
parent dfa0a6da68
commit 88f62f106d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View file

@ -62,7 +62,7 @@ type ZoneSearchResponse struct {
// HostedZone HostedZone.
type HostedZone struct {
ID int `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}
@ -82,34 +82,34 @@ type Record struct {
// getHostedZoneID performs a lookup to get the DNS zone which needs
// modifying for a given FQDN.
func (d *DNSProvider) getHostedZoneID(fqdn string) (int, error) {
func (d *DNSProvider) getHostedZoneID(fqdn string) (string, error) {
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return 0, err
return "", err
}
result, err := d.makeRequest(http.MethodGet, fmt.Sprintf("/domains?name=%s", dns01.UnFqdn(authZone)), nil)
if err != nil {
return 0, err
return "", err
}
var zoneSearchResponse ZoneSearchResponse
err = json.Unmarshal(result, &zoneSearchResponse)
if err != nil {
return 0, err
return "", err
}
// If nothing was returned, or for whatever reason more than 1 was returned (the search uses exact match, so should not occur)
if zoneSearchResponse.TotalEntries != 1 {
return 0, fmt.Errorf("found %d zones for %s in Rackspace for domain %s", zoneSearchResponse.TotalEntries, authZone, fqdn)
return "", fmt.Errorf("found %d zones for %s in Rackspace for domain %s", zoneSearchResponse.TotalEntries, authZone, fqdn)
}
return zoneSearchResponse.HostedZones[0].ID, nil
}
// findTxtRecord searches a DNS zone for a TXT record with a specific name.
func (d *DNSProvider) findTxtRecord(fqdn string, zoneID int) (*Record, error) {
result, err := d.makeRequest(http.MethodGet, fmt.Sprintf("/domains/%d/records?type=TXT&name=%s", zoneID, dns01.UnFqdn(fqdn)), nil)
func (d *DNSProvider) findTxtRecord(fqdn string, zoneID string) (*Record, error) {
result, err := d.makeRequest(http.MethodGet, fmt.Sprintf("/domains/%s/records?type=TXT&name=%s", zoneID, dns01.UnFqdn(fqdn)), nil)
if err != nil {
return nil, err
}

View file

@ -135,7 +135,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
return fmt.Errorf("rackspace: %w", err)
}
_, err = d.makeRequest(http.MethodPost, fmt.Sprintf("/domains/%d/records", zoneID), bytes.NewReader(body))
_, err = d.makeRequest(http.MethodPost, fmt.Sprintf("/domains/%s/records", zoneID), bytes.NewReader(body))
if err != nil {
return fmt.Errorf("rackspace: %w", err)
}
@ -156,7 +156,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
return fmt.Errorf("rackspace: %w", err)
}
_, err = d.makeRequest(http.MethodDelete, fmt.Sprintf("/domains/%d/records?id=%s", zoneID, record.ID), nil)
_, err = d.makeRequest(http.MethodDelete, fmt.Sprintf("/domains/%s/records?id=%s", zoneID, record.ID), nil)
if err != nil {
return fmt.Errorf("rackspace: %w", err)
}

View file

@ -31,7 +31,7 @@ const zoneDetailsMock = `
"domains": [
{
"name": "example.com",
"id": 112233,
"id": "112233",
"emailAddress": "hostmaster@example.com",
"updated": "1970-01-01T00:00:00.000+0000",
"created": "1970-01-01T00:00:00.000+0000"