2016-12-14 13:19:12 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2022-01-05 22:41:41 -08:00
|
|
|
removePrivateFields,
|
|
|
|
|
injectPrivateFields,
|
|
|
|
|
upsert,
|
|
|
|
|
get,
|
|
|
|
|
del,
|
|
|
|
|
wait,
|
|
|
|
|
verifyDomainConfig
|
2016-12-14 13:19:12 -08:00
|
|
|
};
|
|
|
|
|
|
2021-08-13 17:22:28 -07:00
|
|
|
const assert = require('assert'),
|
2019-10-23 10:02:04 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
2017-02-19 20:30:35 -08:00
|
|
|
debug = require('debug')('box:dns/manual'),
|
2022-02-04 13:58:29 -08:00
|
|
|
dig = require('../dig.js'),
|
2021-08-13 17:22:28 -07:00
|
|
|
dns = require('../dns.js'),
|
2022-02-04 13:58:29 -08:00
|
|
|
safe = require('safetydance'),
|
2019-01-04 18:44:54 -08:00
|
|
|
waitForDns = require('./waitfordns.js');
|
2016-12-14 13:19:12 -08:00
|
|
|
|
2019-02-08 11:11:49 +01:00
|
|
|
function removePrivateFields(domainObject) {
|
|
|
|
|
return domainObject;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 10:02:04 -07:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-02-09 19:08:15 +01:00
|
|
|
function injectPrivateFields(newConfig, currentConfig) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
async function upsert(domainObject, location, type, values) {
|
2019-01-04 18:44:54 -08:00
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
2021-05-02 11:26:08 -07:00
|
|
|
assert(Array.isArray(values));
|
2016-12-14 13:19:12 -08:00
|
|
|
|
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
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
return;
|
2016-12-14 13:19:12 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
async function get(domainObject, location, type) {
|
2019-01-04 18:44:54 -08:00
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
|
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
return []; // returning ip confuses apptask into thinking the entry already exists
|
2016-12-14 13:19:12 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
async function del(domainObject, location, type, values) {
|
2019-01-04 18:44:54 -08:00
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
assert.strictEqual(typeof location, 'string');
|
2016-12-14 13:19:12 -08:00
|
|
|
assert.strictEqual(typeof type, 'string');
|
2021-05-02 11:26:08 -07:00
|
|
|
assert(Array.isArray(values));
|
2016-12-14 13:19:12 -08:00
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
return;
|
2016-12-14 13:19:12 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-03 16:15:14 -08:00
|
|
|
async function wait(domainObject, subdomain, type, value, options) {
|
2019-01-04 18:44:54 -08:00
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
2022-02-03 16:15:14 -08:00
|
|
|
assert.strictEqual(typeof subdomain, 'string');
|
2019-01-04 18:44:54 -08:00
|
|
|
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
|
|
|
|
2022-11-28 21:23:06 +01:00
|
|
|
const fqdn = dns.fqdn(subdomain, domainObject.domain);
|
2019-01-04 18:44:54 -08:00
|
|
|
|
2022-02-03 16:15:14 -08:00
|
|
|
await waitForDns(fqdn, domainObject.zoneName, type, value, options);
|
2019-01-04 18:44:54 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
async function verifyDomainConfig(domainObject) {
|
2019-01-04 18:44:54 -08:00
|
|
|
assert.strictEqual(typeof domainObject, 'object');
|
|
|
|
|
|
|
|
|
|
const zoneName = domainObject.zoneName;
|
|
|
|
|
|
2017-11-07 23:13:32 +01:00
|
|
|
// Very basic check if the nameservers can be fetched
|
2022-02-04 13:58:29 -08:00
|
|
|
const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 }));
|
|
|
|
|
if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain');
|
|
|
|
|
if (error || !nameservers) throw new BoxError(BoxError.BAD_FIELD, error ? error.message : 'Unable to get nameservers');
|
2017-01-10 11:49:23 +01:00
|
|
|
|
2022-02-04 13:58:29 -08:00
|
|
|
return {};
|
2017-01-10 11:12:38 +01:00
|
|
|
}
|