diff --git a/CHANGES b/CHANGES index e33d890ae..86f955815 100644 --- a/CHANGES +++ b/CHANGES @@ -2469,3 +2469,5 @@ * Ensure LDAP usernames are always treated lowercase * Add a way to make LDAP users local * proxyAuth: set X-Remote-User (rfc3875) +* GoDaddy: there is now a delete API + diff --git a/src/dns/godaddy.js b/src/dns/godaddy.js index e3e7e745d..8a69e2cf1 100644 --- a/src/dns/godaddy.js +++ b/src/dns/godaddy.js @@ -24,12 +24,6 @@ const assert = require('assert'), // const GODADDY_API_OTE = 'https://api.ote-godaddy.com/v1/domains'; const GODADDY_API = 'https://api.godaddy.com/v1/domains'; -// this is a workaround for godaddy not having a delete API -// https://stackoverflow.com/questions/39347464/delete-record-libcloud-godaddy-api -const GODADDY_INVALID_IP = '0.0.0.0'; -const GODADDY_INVALID_IPv6 = '0:0:0:0:0:0:0:0'; -const GODADDY_INVALID_TXT = '""'; - function formatError(response) { return util.format(`GoDaddy DNS error [${response.statusCode}] ${response.body.message}`); } @@ -106,6 +100,12 @@ async function get(domainObject, location, type) { const values = response.body.map(function (record) { return record.data; }); if (values.length === 1) { + // legacy: this was a workaround for godaddy not having a delete API + // https://stackoverflow.com/questions/39347464/delete-record-libcloud-godaddy-api + const GODADDY_INVALID_IP = '0.0.0.0'; + const GODADDY_INVALID_IPv6 = '0:0:0:0:0:0:0:0'; + const GODADDY_INVALID_TXT = '""'; + if ((type === 'A' && values[0] === GODADDY_INVALID_IP) || (type === 'AAAA' && values[0] === GODADDY_INVALID_IPv6) || (type === 'TXT' && values[0] === GODADDY_INVALID_TXT)) return []; // pretend this record doesn't exist @@ -124,30 +124,17 @@ async function del(domainObject, location, type, values) { zoneName = domainObject.zoneName, name = dns.getName(domainObject, location, type) || '@'; - debug(`get: ${name} in zone ${zoneName} of type ${type} with values ${JSON.stringify(values)}`); + debug(`del: ${name} in zone ${zoneName} of type ${type} with values ${JSON.stringify(values)}`); - if (type !== 'A' && type !== 'AAAA' && type !== 'TXT') throw new BoxError(BoxError.EXTERNAL_ERROR, 'Record deletion is not supported by GoDaddy API'); - - // check if the record exists at all so that we don't insert the "Dead" record for no reason - const existingRecords = await get(domainObject, location, type); - if (existingRecords.length === 0) return; - - // godaddy does not have a delete API. so fill it up with an invalid IP that we can ignore in future get() - const records = [{ - ttl: 600, - data: type === 'A' ? GODADDY_INVALID_IP : (type === 'AAAA' ? GODADDY_INVALID_IPv6 : GODADDY_INVALID_TXT) - }]; - - const [error, response] = await safe(superagent.put(`${GODADDY_API}/${zoneName}/records/${type}/${name}`) + const [error, response] = await safe(superagent.del(`${GODADDY_API}/${zoneName}/records/${type}/${name}`) .set('Authorization', `sso-key ${domainConfig.apiKey}:${domainConfig.apiSecret}`) - .send(records) .timeout(30 * 1000) .ok(() => true)); if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); - if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); + if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } async function wait(domainObject, subdomain, type, value, options) {