2026-02-14 09:53:14 +01:00
|
|
|
import assert from 'node:assert';
|
|
|
|
|
import BoxError from '../boxerror.js';
|
|
|
|
|
import debugModule from 'debug';
|
|
|
|
|
import * as dig from '../dig.js';
|
|
|
|
|
import * as dns from '../dns.js';
|
|
|
|
|
import safe from 'safetydance';
|
|
|
|
|
import waitForDns from './waitfordns.js';
|
2016-12-14 13:19:12 -08:00
|
|
|
|
2026-02-14 09:53:14 +01:00
|
|
|
const debug = debugModule('box:dns/manual');
|
|
|
|
|
|
|
|
|
|
export {
|
2022-01-05 22:41:41 -08:00
|
|
|
removePrivateFields,
|
|
|
|
|
injectPrivateFields,
|
|
|
|
|
upsert,
|
|
|
|
|
get,
|
|
|
|
|
del,
|
|
|
|
|
wait,
|
|
|
|
|
verifyDomainConfig
|
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
|
|
|
}
|