Files
cloudron-box/src/dns/manual.js
T

88 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-12-14 13:19:12 -08:00
'use strict';
exports = module.exports = {
removePrivateFields: removePrivateFields,
injectPrivateFields: injectPrivateFields,
2016-12-14 13:19:12 -08:00
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'),
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'),
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'),
util = require('util'),
waitForDns = require('./waitfordns.js');
2016-12-14 13:19:12 -08:00
function removePrivateFields(domainObject) {
return domainObject;
}
2019-10-23 10:02:04 -07:00
// eslint-disable-next-line no-unused-vars
function injectPrivateFields(newConfig, currentConfig) {
}
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');
2021-05-02 11:26:08 -07:00
assert(Array.isArray(values));
2016-12-14 13:19:12 -08:00
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');
2021-05-02 11:26:08 -07:00
assert(Array.isArray(values));
2016-12-14 13:19:12 -08:00
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;
// 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) {
2019-10-23 10:02:04 -07:00
if (error && error.code === 'ENOTFOUND') return callback(new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain', { field: 'nameservers' }));
if (error || !nameservers) return callback(new BoxError(BoxError.BAD_FIELD, error ? error.message : 'Unable to get nameservers', { field: '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
});
}