asyncify the vultr and DO backend
This commit is contained in:
16
src/dns.js
16
src/dns.js
@@ -33,8 +33,7 @@ const apps = require('./apps.js'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('./settings.js'),
|
||||
sysinfo = require('./sysinfo.js'),
|
||||
tld = require('tldjs'),
|
||||
util = require('util');
|
||||
tld = require('tldjs');
|
||||
|
||||
// choose which subdomain backend we use for test purpose we use route53
|
||||
function api(provider) {
|
||||
@@ -110,18 +109,13 @@ function getName(domain, subdomain, type) {
|
||||
return part ? `${subdomain}.${part}` : subdomain;
|
||||
}
|
||||
|
||||
function maybePromisify(func) {
|
||||
if (util.types.isAsyncFunction(func)) return func;
|
||||
return util.promisify(func);
|
||||
}
|
||||
|
||||
async function getDnsRecords(subdomain, domain, type) {
|
||||
assert.strictEqual(typeof subdomain, 'string');
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof type, 'string');
|
||||
|
||||
const domainObject = await domains.get(domain);
|
||||
return await maybePromisify(api(domainObject.provider).get)(domainObject, subdomain, type);
|
||||
return await api(domainObject.provider).get(domainObject, subdomain, type);
|
||||
}
|
||||
|
||||
async function checkDnsRecords(subdomain, domain) {
|
||||
@@ -156,7 +150,7 @@ async function upsertDnsRecords(subdomain, domain, type, values) {
|
||||
debug(`upsertDNSRecord: location ${subdomain} on domain ${domain} of type ${type} with values ${JSON.stringify(values)}`);
|
||||
|
||||
const domainObject = await domains.get(domain);
|
||||
await maybePromisify(api(domainObject.provider).upsert)(domainObject, subdomain, type, values);
|
||||
await api(domainObject.provider).upsert(domainObject, subdomain, type, values);
|
||||
}
|
||||
|
||||
async function removeDnsRecords(subdomain, domain, type, values) {
|
||||
@@ -168,8 +162,8 @@ async function removeDnsRecords(subdomain, domain, type, values) {
|
||||
debug('removeDNSRecord: %s on %s type %s values', subdomain, domain, type, values);
|
||||
|
||||
const domainObject = await domains.get(domain);
|
||||
const [error] = await safe(maybePromisify(api(domainObject.provider).del)(domainObject, subdomain, type, values));
|
||||
if (error && error.reason !== BoxError.NOT_FOUND) throw error;
|
||||
const [error] = await safe(api(domainObject.provider).del(domainObject, subdomain, type, values));
|
||||
if (error && error.reason !== BoxError.NOT_FOUND) throw error; // this is never returned afaict
|
||||
}
|
||||
|
||||
async function waitForDnsRecord(subdomain, domain, type, value, options) {
|
||||
|
||||
Reference in New Issue
Block a user