2016-12-14 13:19:12 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
|
upsert: upsert,
|
|
|
|
|
get: get,
|
|
|
|
|
del: del,
|
2019-01-04 18:44:54 -08:00
|
|
|
wait: wait,
|
2017-01-10 11:12:38 +01:00
|
|
|
verifyDnsConfig: verifyDnsConfig
|
2016-12-14 13:19:12 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var assert = require('assert'),
|
2017-02-19 20:30:35 -08:00
|
|
|
debug = require('debug')('box:dns/manual'),
|
2018-02-08 10:21:31 -08:00
|
|
|
dns = require('../native-dns.js'),
|
2019-01-04 18:44:54 -08:00
|
|
|
domains = require('../domains.js'),
|
2018-04-29 11:20:12 -07:00
|
|
|
DomainsError = require('../domains.js').DomainsError,
|
2019-01-04 18:44:54 -08:00
|
|
|
util = require('util'),
|
|
|
|
|
waitForDns = require('./waitfordns.js');
|
2016-12-14 13:19:12 -08:00
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
function upsert(domainObject, location, type, values, callback) {
|
|
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
|
|
|
|
assert(util.isArray(values));
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
debug('upsert: %s for zone %s of type %s with values %j', location, domainObject.zoneName, type, values);
|
2016-12-14 13:19:12 -08:00
|
|
|
|
2018-06-29 22:25:34 +02:00
|
|
|
return callback(null);
|
2016-12-14 13:19:12 -08:00
|
|
|
}
|
|
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
function get(domainObject, location, type, callback) {
|
|
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
callback(null, [ ]); // returning ip confuses apptask into thinking the entry already exists
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
function del(domainObject, location, type, values, callback) {
|
|
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
|
|
|
|
assert(util.isArray(values));
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
function wait(domainObject, location, type, value, options, callback) {
|
|
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
|
|
|
|
assert.strictEqual(typeof type, 'string');
|
|
|
|
|
assert.strictEqual(typeof value, 'string');
|
|
|
|
|
assert(options && typeof options === 'object'); // { interval: 5000, times: 50000 }
|
2017-01-10 11:12:38 +01:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-01-04 18:44:54 -08:00
|
|
|
const fqdn = domains.fqdn(location, domainObject);
|
|
|
|
|
|
|
|
|
|
waitForDns(fqdn, domainObject.zoneName, type, value, options, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function verifyDnsConfig(domainObject, callback) {
|
|
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
|
|
|
|
const zoneName = domainObject.zoneName;
|
|
|
|
|
|
2017-11-07 23:13:32 +01:00
|
|
|
// Very basic check if the nameservers can be fetched
|
2018-02-08 14:39:35 -08:00
|
|
|
dns.resolve(zoneName, 'NS', { timeout: 5000 }, function (error, nameservers) {
|
2018-05-15 12:23:41 -07:00
|
|
|
if (error && error.code === 'ENOTFOUND') return callback(new DomainsError(DomainsError.BAD_FIELD, 'Unable to resolve nameservers for this domain'));
|
|
|
|
|
if (error || !nameservers) return callback(new DomainsError(DomainsError.BAD_FIELD, error ? error.message : 'Unable to get nameservers'));
|
2017-01-10 11:49:23 +01:00
|
|
|
|
2018-09-11 21:24:04 -07:00
|
|
|
callback(null, {});
|
2017-01-10 11:12:38 +01:00
|
|
|
});
|
|
|
|
|
}
|