diff --git a/src/apptask.js b/src/apptask.js index 1fd93ec69..7f90c5290 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -253,7 +253,7 @@ function registerSubdomain(app, callback) { async.retry({ times: 200, interval: 5000 }, function (retryCallback) { debugApp(app, 'Registering subdomain location [%s]', app.location); - subdomains.update(app.location, 'A', [ ip ], function (error, changeId) { + subdomains.upsert(app.location, 'A', [ ip ], function (error, changeId) { if (error && (error.reason === SubdomainError.STILL_BUSY || error.reason === SubdomainError.EXTERNAL_ERROR)) return retryCallback(error); // try again retryCallback(null, error || changeId); diff --git a/src/cloudron.js b/src/cloudron.js index f3b58e29b..d0096814c 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -453,7 +453,7 @@ function addDnsRecords() { debug('addDnsRecords: will update %j', records); async.mapSeries(records, function (record, iteratorCallback) { - subdomains.update(record.subdomain, record.type, record.values, iteratorCallback); + subdomains.upsert(record.subdomain, record.type, record.values, iteratorCallback); }, function (error, changeIds) { if (error) debug('addDnsRecords: failed to update : %s. will retry', error); else debug('addDnsRecords: records %j added with changeIds %j', records, changeIds); diff --git a/src/dns/caas.js b/src/dns/caas.js index 43b0b71e3..8192445e6 100644 --- a/src/dns/caas.js +++ b/src/dns/caas.js @@ -3,7 +3,7 @@ exports = module.exports = { add: add, del: del, - update: update, + upsert: upsert, getChangeStatus: getChangeStatus, get: get }; @@ -69,7 +69,7 @@ function get(dnsConfig, zoneName, subdomain, type, callback) { }); } -function update(dnsConfig, zoneName, subdomain, type, values, callback) { +function upsert(dnsConfig, zoneName, subdomain, type, values, callback) { assert.strictEqual(typeof dnsConfig, 'object'); assert.strictEqual(typeof zoneName, 'string'); assert.strictEqual(typeof subdomain, 'string'); @@ -77,13 +77,7 @@ function update(dnsConfig, zoneName, subdomain, type, values, callback) { assert(util.isArray(values)); assert.strictEqual(typeof callback, 'function'); - get(dnsConfig, zoneName, subdomain, type, function (error, result) { - if (error) return callback(error); - - if (_.isEqual(values, result)) return callback(); - - add(dnsConfig, zoneName, subdomain, type, values, callback); - }); + add(dnsConfig, zoneName, subdomain, type, values, callback); } function del(dnsConfig, zoneName, subdomain, type, values, callback) { diff --git a/src/dns/route53.js b/src/dns/route53.js index 98d98ca59..127a65a92 100644 --- a/src/dns/route53.js +++ b/src/dns/route53.js @@ -4,7 +4,7 @@ exports = module.exports = { add: add, get: get, del: del, - update: update, + upsert: upsert, getChangeStatus: getChangeStatus, // not part of "dns" interface @@ -113,7 +113,7 @@ function add(dnsConfig, zoneName, subdomain, type, values, callback) { }); } -function update(dnsConfig, zoneName, subdomain, type, values, callback) { +function upsert(dnsConfig, zoneName, subdomain, type, values, callback) { assert.strictEqual(typeof dnsConfig, 'object'); assert.strictEqual(typeof zoneName, 'string'); assert.strictEqual(typeof subdomain, 'string'); @@ -121,13 +121,7 @@ function update(dnsConfig, zoneName, subdomain, type, values, callback) { assert(util.isArray(values)); assert.strictEqual(typeof callback, 'function'); - get(dnsConfig, zoneName, subdomain, type, function (error, result) { - if (error) return callback(error); - - if (_.isEqual(values, result)) return callback(); - - add(dnsConfig, zoneName, subdomain, type, values, callback); - }); + add(dnsConfig, zoneName, subdomain, type, values, callback); } function get(dnsConfig, zoneName, subdomain, type, callback) { diff --git a/src/platform.js b/src/platform.js index 61cfad961..2c7376c2f 100644 --- a/src/platform.js +++ b/src/platform.js @@ -269,7 +269,7 @@ function startMail(callback) { // Add MX record var mxRecord = { subdomain: '', type: 'MX', values: [ '10 ' + config.mailFqdn() + '.' ] }; - subdomains.update(mxRecord.subdomain, mxRecord.type, mxRecord.values, callback); + subdomains.upsert(mxRecord.subdomain, mxRecord.type, mxRecord.values, callback); }); }); }); diff --git a/src/subdomains.js b/src/subdomains.js index 62ec8e25f..9cd3a92ec 100644 --- a/src/subdomains.js +++ b/src/subdomains.js @@ -4,7 +4,7 @@ module.exports = exports = { add: add, remove: remove, status: status, - update: update, // unlike add, this fetches latest value, compares and adds if necessary. atomicity depends on backend + upsert: upsert, get: get, SubdomainError: SubdomainError @@ -88,7 +88,7 @@ function get(subdomain, type, callback) { }); } -function update(subdomain, type, values, callback) { +function upsert(subdomain, type, values, callback) { assert.strictEqual(typeof subdomain, 'string'); assert.strictEqual(typeof type, 'string'); assert(util.isArray(values)); @@ -97,7 +97,7 @@ function update(subdomain, type, values, callback) { settings.getDnsConfig(function (error, dnsConfig) { if (error) return callback(new SubdomainError(SubdomainError.INTERNAL_ERROR, error)); - api(dnsConfig.provider).update(dnsConfig, config.zoneName(), subdomain, type, values, function (error, changeId) { + api(dnsConfig.provider).upsert(dnsConfig, config.zoneName(), subdomain, type, values, function (error, changeId) { if (error) return callback(error); callback(null, changeId);