dnsConfig -> domainConfig

this prepares for the incoming settings.getDnsConfig()
This commit is contained in:
Girish Ramakrishnan
2022-01-05 22:41:41 -08:00
parent bbf1a5af3d
commit bf51bc25e9
21 changed files with 342 additions and 342 deletions
+28 -28
View File
@@ -7,7 +7,7 @@ exports = module.exports = {
get,
del,
wait,
verifyDnsConfig
verifyDomainConfig
};
const assert = require('assert'),
@@ -34,8 +34,8 @@ function injectPrivateFields(newConfig, currentConfig) {
if (newConfig.token === constants.SECRET_PLACEHOLDER) newConfig.token = currentConfig.token;
}
function addRecord(dnsConfig, zoneName, name, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
function addRecord(domainConfig, zoneName, name, type, values, callback) {
assert.strictEqual(typeof domainConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof type, 'string');
@@ -62,7 +62,7 @@ function addRecord(dnsConfig, zoneName, name, type, values, callback) {
}
superagent.post(`${NAMECOM_API}/domains/${zoneName}/records`)
.auth(dnsConfig.username, dnsConfig.token)
.auth(domainConfig.username, domainConfig.token)
.timeout(30 * 1000)
.send(data)
.end(function (error, result) {
@@ -74,8 +74,8 @@ function addRecord(dnsConfig, zoneName, name, type, values, callback) {
});
}
function updateRecord(dnsConfig, zoneName, recordId, name, type, values, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
function updateRecord(domainConfig, zoneName, recordId, name, type, values, callback) {
assert.strictEqual(typeof domainConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof recordId, 'number');
assert.strictEqual(typeof name, 'string');
@@ -103,7 +103,7 @@ function updateRecord(dnsConfig, zoneName, recordId, name, type, values, callbac
}
superagent.put(`${NAMECOM_API}/domains/${zoneName}/records/${recordId}`)
.auth(dnsConfig.username, dnsConfig.token)
.auth(domainConfig.username, domainConfig.token)
.timeout(30 * 1000)
.send(data)
.end(function (error, result) {
@@ -115,8 +115,8 @@ function updateRecord(dnsConfig, zoneName, recordId, name, type, values, callbac
});
}
function getInternal(dnsConfig, zoneName, name, type, callback) {
assert.strictEqual(typeof dnsConfig, 'object');
function getInternal(domainConfig, zoneName, name, type, callback) {
assert.strictEqual(typeof domainConfig, 'object');
assert.strictEqual(typeof zoneName, 'string');
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof type, 'string');
@@ -125,7 +125,7 @@ function getInternal(dnsConfig, zoneName, name, type, callback) {
debug(`getInternal: ${name} in zone ${zoneName} of type ${type}`);
superagent.get(`${NAMECOM_API}/domains/${zoneName}/records`)
.auth(dnsConfig.username, dnsConfig.token)
.auth(domainConfig.username, domainConfig.token)
.timeout(30 * 1000)
.end(function (error, result) {
if (error && !error.response) return callback(new BoxError(BoxError.NETWORK_ERROR, error.message));
@@ -158,18 +158,18 @@ function upsert(domainObject, location, type, values, callback) {
assert(Array.isArray(values));
assert.strictEqual(typeof callback, 'function');
const dnsConfig = domainObject.config,
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName,
name = dns.getName(domainObject, location, type) || '';
debug(`upsert: ${name} in zone ${zoneName} of type ${type} with values ${JSON.stringify(values)}`);
getInternal(dnsConfig, zoneName, name, type, function (error, result) {
getInternal(domainConfig, zoneName, name, type, function (error, result) {
if (error) return callback(error);
if (result.length === 0) return addRecord(dnsConfig, zoneName, name, type, values, callback);
if (result.length === 0) return addRecord(domainConfig, zoneName, name, type, values, callback);
return updateRecord(dnsConfig, zoneName, result[0].id, name, type, values, callback);
return updateRecord(domainConfig, zoneName, result[0].id, name, type, values, callback);
});
}
@@ -179,11 +179,11 @@ function get(domainObject, location, type, callback) {
assert.strictEqual(typeof type, 'string');
assert.strictEqual(typeof callback, 'function');
const dnsConfig = domainObject.config,
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName,
name = dns.getName(domainObject, location, type) || '';
getInternal(dnsConfig, zoneName, name, type, function (error, result) {
getInternal(domainConfig, zoneName, name, type, function (error, result) {
if (error) return callback(error);
var tmp = result.map(function (record) { return record.answer; });
@@ -201,19 +201,19 @@ function del(domainObject, location, type, values, callback) {
assert(Array.isArray(values));
assert.strictEqual(typeof callback, 'function');
const dnsConfig = domainObject.config,
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName,
name = dns.getName(domainObject, location, type) || '';
debug(`del: ${name} in zone ${zoneName} of type ${type} with values ${JSON.stringify(values)}`);
getInternal(dnsConfig, zoneName, name, type, function (error, result) {
getInternal(domainConfig, zoneName, name, type, function (error, result) {
if (error) return callback(error);
if (result.length === 0) return callback();
superagent.del(`${NAMECOM_API}/domains/${zoneName}/records/${result[0].id}`)
.auth(dnsConfig.username, dnsConfig.token)
.auth(domainConfig.username, domainConfig.token)
.timeout(30 * 1000)
.end(function (error, result) {
if (error && !error.response) return callback(new BoxError(BoxError.NETWORK_ERROR, error.message));
@@ -238,19 +238,19 @@ function wait(domainObject, location, type, value, options, callback) {
waitForDns(fqdn, domainObject.zoneName, type, value, options, callback);
}
function verifyDnsConfig(domainObject, callback) {
function verifyDomainConfig(domainObject, callback) {
assert.strictEqual(typeof domainObject, 'object');
assert.strictEqual(typeof callback, 'function');
const dnsConfig = domainObject.config,
const domainConfig = domainObject.config,
zoneName = domainObject.zoneName;
if (typeof dnsConfig.username !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'username must be a string', { field: 'username' }));
if (typeof dnsConfig.token !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'token must be a string', { field: 'token' }));
if (typeof domainConfig.username !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'username must be a string', { field: 'username' }));
if (typeof domainConfig.token !== 'string') return callback(new BoxError(BoxError.BAD_FIELD, 'token must be a string', { field: 'token' }));
var credentials = {
username: dnsConfig.username,
token: dnsConfig.token
username: domainConfig.username,
token: domainConfig.token
};
const ip = '127.0.0.1';
@@ -262,7 +262,7 @@ function verifyDnsConfig(domainObject, callback) {
if (error || !nameservers) return callback(new BoxError(BoxError.BAD_FIELD, error ? error.message : 'Unable to get nameservers', { field: 'nameservers' }));
if (!nameservers.every(function (n) { return n.toLowerCase().indexOf('.name.com') !== -1; })) {
debug('verifyDnsConfig: %j does not contain Name.com NS', nameservers);
debug('verifyDomainConfig: %j does not contain Name.com NS', nameservers);
return callback(new BoxError(BoxError.BAD_FIELD, 'Domain nameservers are not set to name.com', { field: 'nameservers' }));
}
@@ -271,12 +271,12 @@ function verifyDnsConfig(domainObject, callback) {
upsert(domainObject, location, 'A', [ ip ], function (error) {
if (error) return callback(error);
debug('verifyDnsConfig: Test A record added');
debug('verifyDomainConfig: Test A record added');
del(domainObject, location, 'A', [ ip ], function (error) {
if (error) return callback(error);
debug('verifyDnsConfig: Test A record removed again');
debug('verifyDomainConfig: Test A record removed again');
callback(null, credentials);
});